- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Comparing between different filters on the same data
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-05-2018 09:43 AM - edited 06-05-2018 09:45 AM
Say I have data like this:
Date | Account | Statistic | Value |
30/06/2017 | 1 | Alpha | 0.85 |
30/06/2017 | 2 | Alpha | 0.34 |
30/06/2017 | 1 | Beta | 0.52 |
30/06/2017 | 2 | Beta | 0.29 |
30/06/2017 | 1 | Gamma | 0.14 |
30/06/2017 | 2 | Gamma | 0.25 |
31/07/2017 | 1 | Alpha | 0.35 |
31/07/2017 | 2 | Alpha | 0.23 |
31/07/2017 | 1 | Beta | 0.51 |
31/07/2017 | 2 | Beta | 0.26 |
31/07/2017 | 1 | Gamma | 0.16 |
31/07/2017 | 2 | Gamma | 0.90 |
31/08/2017 | 1 | Alpha | 0.88 |
31/08/2017 | 2 | Alpha | 0.20 |
31/08/2017 | 1 | Beta | 0.76 |
31/08/2017 | 2 | Beta | 0.79 |
31/08/2017 | 1 | Gamma | 0.83 |
31/08/2017 | 2 | Gamma | 0.66 |
Now imagine I have two bar charts (one per Account), with Date on X and Value on Y, and the different Statistics as different bars.
[In reality there are a lot more Accounts, and there are two slicers to select the two Accounts we want to compare.]
How can I get a third chart that shows the Value difference between the two, again per Date and Statistic?
I started by creating a duplicate of the dataset and now want to do something like https://community.powerbi.com/t5/Desktop/How-to-calculate-difference-after-different-filter-settings... - but there is no sensible way to relate the table with its duplicate.
There must a way to do this surely?
Solved! Go to Solution.
Accepted Solutions
Re: Comparing between different filters on the same data
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-05-2018 08:16 PM - edited 06-05-2018 08:17 PM
Hi @olik,
You can try the below method as well!!! FYI, I have the data that you have provided for this purpose
The Following are the steps.
1. Have 2 copies of your data (namely Table1 and Table2)
2. Join the tables based on Date Column
3. Create the following 2 measures
In Table1
Measure 1 = CALCULATE(SUM(Table1[Value]), FILTER(Table1, Table1[Account] = SELECTEDVALUE(Table1[Account])))
In Table2
Measure 2 = CALCULATE(SUM(Table2[Value]), FILTER(Table2, Table2[Account] = SELECTEDVALUE(Table2[Account])))
Create another measure to find the difference between the measures
Measure = [Measure 1] - [Measure 2]
Relationship, more likely to look like (not necessarily have to be same)
Relationship between tables through a bridge table
My Output looked as shown below
Output
As you change the accounts in your slicer, you value changes correspondingly....
Hope this helps you get what you needed!!!
regards,
Thejeswar
Re: Comparing between different filters on the same data
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-07-2018 06:56 AM
Thanks a lot! I used your suggestion and made the formula even easier:
Result = SUM(Table1[Value]) - CALCULATE(SUM(Table1[Value]), FILTER(ALL(Table1[Account]),Table1[Account] = SELECTEDVALUE(Table2[Account])))
That way I only need one measure, and technically I don't even need the full duplicate table... Just another list of accounts would do!
Do you see any issues with my approach? Still very new to the whole DAX coding!
All Replies
Re: Comparing between different filters on the same data
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-05-2018 02:54 PM
I think I have found a way, using an additional measure based on SELECTEDVALUE parameters and then defined as such:
CALCULATE
(
AVERAGE(Table1[Value]),
FILTER(
ALL(Table1[Account]),
[Account]=Table2[Selected Account]
)
)
Surely that can't be the best way though?
Re: Comparing between different filters on the same data
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-05-2018 08:16 PM - edited 06-05-2018 08:17 PM
Hi @olik,
You can try the below method as well!!! FYI, I have the data that you have provided for this purpose
The Following are the steps.
1. Have 2 copies of your data (namely Table1 and Table2)
2. Join the tables based on Date Column
3. Create the following 2 measures
In Table1
Measure 1 = CALCULATE(SUM(Table1[Value]), FILTER(Table1, Table1[Account] = SELECTEDVALUE(Table1[Account])))
In Table2
Measure 2 = CALCULATE(SUM(Table2[Value]), FILTER(Table2, Table2[Account] = SELECTEDVALUE(Table2[Account])))
Create another measure to find the difference between the measures
Measure = [Measure 1] - [Measure 2]
Relationship, more likely to look like (not necessarily have to be same)
Relationship between tables through a bridge table
My Output looked as shown below
Output
As you change the accounts in your slicer, you value changes correspondingly....
Hope this helps you get what you needed!!!
regards,
Thejeswar
Re: Comparing between different filters on the same data
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-07-2018 06:56 AM
Thanks a lot! I used your suggestion and made the formula even easier:
Result = SUM(Table1[Value]) - CALCULATE(SUM(Table1[Value]), FILTER(ALL(Table1[Account]),Table1[Account] = SELECTEDVALUE(Table2[Account])))
That way I only need one measure, and technically I don't even need the full duplicate table... Just another list of accounts would do!
Do you see any issues with my approach? Still very new to the whole DAX coding!
Re: Comparing between different filters on the same data
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-07-2018 08:14 PM
Hi @olik,
Your re-did DAX looks fine.
I think the new DAX that you have written should be good enough to get the difference
Regards,
Thejeswar
Re: Comparing between different filters on the same data
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-12-2018 06:30 PM
Hi @olik,
Could you please mark the proper answers as solutions?
Best Regards,
Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.