Drill down report in power bi after a comparaison in power query - merge

I am comparing two datasets with Power Query.
The two datasets are as follows:
Fist dataset:
|---------------------|------------------|
| Planet | Species |
|---------------------|------------------|
| Neptune | 45 453 |
|---------------------|------------------|
| Mars | 76 |
|---------------------|------------------|
Second dataset:
|---------------------|------------------|------------------|
| Planet | Species | SubSpecies |
|---------------------|------------------|------------------|
| Neptune | 45 453 | BOUB |
|---------------------|------------------|------------------|
| Mars | 76 | BIB |
|---------------------|------------------|------------------|
| Neptune | 45 453 | BOUB |
|---------------------|------------------|------------------|
| Mars | 77 | BOUB |
|---------------------|------------------|------------------|
| Mars | 77 | BIB |
|---------------------|------------------|------------------|
I look if one "couple" (Planet/Species) exist in one file but not in the other, and it it is the case I underline this in my report.
The power BI report shows this, in my example, because the couple Mars/77 is new:
|---------------------|------------------|
| Mars | 77 |
|---------------------|------------------|
I identify what is missing by simply merging queries in power query.
However I would like to have the ability to "drill down" in sub-speicies.
For example, lets say that for the first time a species is observed in one planet in one of the file, I would like to have the ability to show in the report the sub-type.
In this case, the output, besides showing that for the first time speicies 77 has been observed on Mars, would show this:
|---------------------|------------------|------------------|
| Mars | 77 | BOUB |
|---------------------|------------------|------------------|
| Mars | 77 | BIB |
|---------------------|------------------|------------------|
I do not know how to do that and I do not know if doing this in power query is possible or if I would need to use DAX in parallel or in complement.

Related

How to use Tableau TOTAL() on WINDOWS_SUM()

In my tableau workbook, I have a calculated field - "Rolling 12 Month Sales" having the below formula and its working fine.
WINDOWS_SUM(SUM(Sales),-11,0)
Now , I am trying to achieve a Rolling 12 Month Sales % measure.
For this % measure, I am referring an existing calculation - SUM(Sales)/TOTAL(SUM(Sales)) - When this is cut on various segments, I get the percent distribution.
I am trying to get the exact same thing, on the Rolling 12 Month Sales % calculation. I tried the following but its not allowing to use a table calculation inside TOTAL()
WINDOWS_SUM(SUM(Sales),-11,0)/TOTAL(WINDOWS_SUM(SUM(Sales),-11,0))
Original Data
+--------+----------+----------+
| Month | Hardware | Software |
+--------+----------+----------+
| Jan-20 | 5000 | 7500 |
| Feb-20 | 6500 | 10000 |
| Mar-20 | 8000 | 10500 |
| Apr-20 | 11000 | 15000 |
| May-20 | 13500 | 21000 |
+--------+----------+----------+
Rolling 2 Months Sum Sales (This is working fine)
+--------+----------+----------+
| Month | Hardware | Software |
+--------+----------+----------+
| Jan-20 | 5000 | 7500 |
| Feb-20 | 11500 | 17500 |
| Mar-20 | 19500 | 28000 |
| Apr-20 | 25500 | 35500 |
| May-20 | 32500 | 46500 |
+--------+----------+----------+
Rolling 2 Months Sum Sales % - Below are the nos I am trying to achieve.
+--------+----------+----------+
| Month | Hardware | Software |
+--------+----------+----------+
| Jan-20 | 40.00% | 60.00% |
| Feb-20 | 39.66% | 60.34% |
| Mar-20 | 41.05% | 58.95% |
| Apr-20 | 41.80% | 58.20% |
| May-20 | 41.14% | 58.86% |
+--------+----------+----------+
Running out of options!
Best Regards
There should be no need to TOTAL a WINDOW_SUM. I suspect this could be solved with different Compute Using. But first I don't fully understand why you're taking the approach you are attempting. Any chance you could show some sample data with the results you expect along the way? For simplicity in the example it would be easier to do a rolling 2 periods rather than 12.

PostgreSQL Need rows to return even if the result is 0

I know this has been asked a bit on here and I have tried several of the answers with no progress. My goal is to be able to also see which Tracking Numbers had 0 calls during the date range.
I have tried several joins, sub-queries, and way to much time. Any help would be greatly appreciated.
SELECT org_unit_name "Group Name",
call_detail.ring_to_name "Ad Source(s)",
tracking "Tracking Number",
COUNT(call.call_id)"Calls",
SUM(bill_second)/60 "Total Duration (Sec)"
FROM CALL
JOIN call_detail ON call.call_id = call_detail.call_id
JOIN org_unit o ON call.org_unit_id = o.org_unit_id
WHERE billing_id = 3104
AND call_started BETWEEN '2020-01-01' AND '2020-01-31'
GROUP BY 1,2,3
Here is a sample of how the data is coming back:
| Group Name | Ad Source(s) | Tracking Number | Calls | Total Duration (Sec) |
|--------------------------|------------------------------|-----------------|-------|----------------------|
| Westin Riverfront Villas | Desert Willow Explorer | 8883926768 | 2 | 9 |
| Sheraton Maui | Postcard-Owner | 8885322865 | 36 | 82 |
| Westin Maui | CS On-Site Pre Arrival calls | 8885939052 | 35 | 128 |
| Sheraton Kauai | Email Renter | 8887248492 | 24 | 91 |
But I need 6th and 8th line to show up as well even/especially since they have had no calls.
Westin Princeville and Westin Nanea Resort had no calls but should be on the report
| Group Name | Ad Source(s) | Tracking Number | Calls | Total Duration (Sec) |
|--------------------------|---------------------------------|-----------------|-------|----------------------|
| Westin Maui | CS On-Site Pre Arrival calls | 8885939052 | 35 | 128 |
| Westin Riverfront Villas | Desert Willow Explorer | 8883926768 | 2 | 9 |
| Sheraton Kauai | Email Renter | 8887248492 | 24 | 91 |
| Westin Princeville | In-House pre-arrival phone call | 8776921840 | 0 | 0 |
| Sheraton Maui | Postcard-Owner | 8885322865 | 36 | 82 |
| Westin Nanea Resort | Pre-Arrival E-Mail Nanea WVP | 8887218839 | 0 | 0 |

asof (aj) join strictly less than in KDB/Q

I have a quote table and trade table, and would like to list the quotes table and join in the trades table matching on timestamps strictly less than the timestamp of the trade.
For example:
q:([]time:10:00:00 10:01:00 10:01:00 10:01:02;sym:`ibm`ibm`ibm`ibm;qty:100 200 300 400)
t:([]time:10:01:00 10:01:00 10:01:02;sym:`ibm`ibm`ibm;px:10 20 25)
aj[`time;q;t]
returns
+------------+-----+-----+----+
| time | sym | qty | px |
+------------+-----+-----+----+
| 10:00:00 | ibm | 100 | |
| 10:01:00 | ibm | 200 | 20 |
| 10:01:00 | ibm | 300 | 20 |
| 10:01:02 | ibm | 400 | 25 |
+------------+-----+-----+----+
But I'm trying to get a result like:
+------------+-----+-----+----+
| time | sym | qty | px |
+------------+-----+-----+----+
| 10:00:00 | ibm | 100 | |
| 10:01:00 | ibm | 100 | 10 |
| 10:01:00 | ibm | 100 | 20 |
| 10:01:02 | ibm | 300 | 25 |
+------------+-----+-----+----+
Is there a join function that can match based on timestamps that are strictly less than time instead up-to and including?
I think if you do some variation of aj[`time;q;t] then you won't be able to modify the qty column as table t does not contain it. Instead you may need to use the more "traditional" aj[`time;t;q]:
q)#[;`time;+;00:00:01]aj[`time;#[t;`time;-;00:00:01];q]
time sym px qty
-------------------
10:01:00 ibm 10 100
10:01:00 ibm 20 100
10:01:02 ibm 25 300
This shifts the times to avoid matching where they are equal but does not contain a row for each quote you had in the beginning.
I think if you wish to join trades to quotes rather than quotes to trades as I have done you may need to think of some method of differentiating between 2 trades that occur at the same time as in your example. One method to do this may be to use the order they arrive, i.e. match first quote to first trade.
One “hacking” way I’m thinking is to just shift all trades by the minimum time unit do the aj and then shift back

Dynamic groups in Postgresql data

I have a PostgreSQL 9.1 database with a table containing measurement data, which contains setpoint information. For example temperature setpoints. The measurements are taken when at a setpoint, after which the following setpoint will be set. A setpoint can be reached multiple times, e.g. -25, 25, 75, 125, 75, 25 degree Celcius. In this case 25 and 75 degree Celcius are reached multiple times.
Now I want to group the data per setpoint, but not group data together of another setpoint that has the same value but is reached at a later point in time.
Example data:
| id | setpoint | value |<dyn.group>|
| 1 | -25 | 5.324 | 1
| 2 | -25 | 6.343 | 1
| 3 | -25 | 6.432 | 1
| 4 | 25 | 3.432 | 2
| 5 | 25 | 4.472 | 2
| 6 | 25 | 6.221 | 2
| 7 | 75 | 5.142 | 3
| 8 | 75 | 7.922 | 3
| 9 | 75 | 3.832 | 3
|10 | 125 | 8.882 | 4
|11 | 125 | 9.742 | 4
|12 | 125 | 7.632 | 4
|13 | 75 | 5.542 | 5
|14 | 75 | 2.452 | 5
|15 | 75 | 1.332 | 5
|16 | 25 | 3.232 | 6
|17 | 25 | 4.132 | 6
|18 | 25 | 5.432 | 6
Normal group by clauses will fail, because setpoint can be there multiple times, but should not be put together.
Looking with LEAD and LAG to the previous/next values is also not desired, because changes will most likely be similar (e.g. if setpoint 75 is repeated, then most likely the step from 25->75 will also be repeated).
The expected outcome is the 4th column (<dyn.group>). With that column I can for example average on these groups.
It can be done with a custom aggregation function to generate the "group index" value and then a "group by" clause in that value.

How can I combine two similar columns in Tableau?

I am using Tableau Public to read data from a '|' separated text file. The goal is to determine how much damage each player dealt versus received. Currently the data only shows rows for each attacker. How can I change the data so that I see a row for each player?
Sample Source:
Attacker Name | Attacker Nation | Defender Name | Defender Nation | Attacking Damage | Defending Damage
Bob | Builder | Felix | Fixer | 100 | 120
Bob | Builder | Ralph | Wrecker | 150 | 75
Felix | Fixer | Ralph | Wrecker | 125 | 150
Desired Output:
Name | Nation | Opponent Name | Opponent Nation | Damage Dealt | Damage Received
Bob | Builder | Felix | Fixer | 100 | 120
Bob | Builder | Ralph | Wrecker | 150 | 75
Felix | Fixer | Bob | Builder | 120 | 100
Felix | Fixer | Ralph | Wrecker | 125 | 150
Ralph | Wrecker | Bob | Builder | 75 | 150
Ralph | Wrecker | Felix | Fixer | 150 | 125