Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PowerBI-Newbie
Helper III
Helper III

Help with Multiple Filters from User Selection Slicers

Hi,

I have a calendar table which has columns Year and Period that I'm using as slicers:

Power BI Report-Dashboard-Calendar Data.PNG

 

I'm using these to filter out data from 6 data tables; these 6 tables also contain the columns Year and Period. When I previously had data for Year 19-20 only the figures were calculated correctly but when I've now added data for Year 20-21 I'm getting a summation of Years 19-20 and 20-21 instead of just the Year and Period selected.


I have the following data as an example:

Power BI Report-Dashboard-SIP Data.PNG

 

The slicers are as follows:

Power BI Report-Dashboard-Slicers.PNG

 

When I select the Year and Period then the calculations are made based on this user selection. I have the following KPIs that I'm calculating:

Period calculation measure:
SIP Actual = (sum(SIP_Activities[Actual-LD]) + sum(SIP_Activities[Late Delivery]))
 
YTD calculation measure:
SIP Actual (YTD) =
CALCULATE (
SUMX('SIP_Activities', [SIP Actual]),
FILTER (
ALLEXCEPT ( 'Calendar_Table', 'Calendar_Table'[Year]),
'Calendar_Table'[Period] <= MAX ( 'Calendar_Table'[Period] )
)
)
 
I had many-many relationship and single direction (calendar table filtering the respective table) which worked fine until I had data for the new fiscal year. So now when I select Year 20-21 and Period 1 I'm getting 10 for Planned instead of 1, and consequently my YTD figure for the new financial year should 1 for Planned instead of 10.
Any help is greatly appreciated. 
1 ACCEPTED SOLUTION

A bit tricky, but a disconnected table trick and this measure later and I think I got it. PBIX is attached:

SIP Actual Line Chart = 
    VAR __Year = MAX('SIP_Activities'[Year])
    VAR __Period = MAX('SIP_Activities'[Period]) + 0
    VAR __LinePeriod = MAX('Periods'[Period]) + 0
    VAR __Table = FILTER(ALL(SIP_Activities),[Year] = __Year && [Period]+0 <= __Period)
    VAR __Table1 = FILTER(__Table,[Period]+0 = __LinePeriod)
RETURN
    SUMX(__Table1,[Actual-LD]) + SUMX(__Table1,[Late Delivery])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

23 REPLIES 23
amitchandak
Super User
Super User

@PowerBI-Newbie , In case you have date, prefer using time intelligence

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((Table[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR(Table[Date])),"12/31"))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd(Table[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd(Table[Date],-1,Year)),"12/31"))

Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd(Table[Date],-2,Year),"12/31"))

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd(Table[Date],-1,Year))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Hi @amitchandak ,

Thank you for your response.

 

Unfortunately we don't use date for this particular dashboard, it's only Fiscal Year and Period as per my data.

Greg_Deckler
Super User
Super User

If you could post the data as text could potentially recreate, otherwise nice job of following the principles in this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

However, I am thinking what you need to do is create two a new column in each of your tables that concatenates your year and period. Then create a new table Table = DISTINCT('Table1or2'[YearPeriod]).

 

Then use that in your slicer? Many to many relationships are generally bad.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

 

Thank you for your quick response.

 

Here's the data as text:

Calendar:

YearPeriod
19-201
19-202
19-203
19-204
19-205
19-206
19-207
19-208
19-209
19-2010
19-2011
19-2012
19-2013
20-211
20-212
20-213
20-214
20-215
20-216
20-217
20-218
20-219
20-2110
20-2111
20-2112
20-2113

 

 

Data:

 

YearPeriodPlannedActual
19-20199
19-2021515
19-2031617
19-2041415
19-2051210
19-2061313
19-2071013
19-2081113
19-20999
19-20101213
19-201199
19-20121012
19-201393
20-21111
20-21222
20-21333
20-21444
20-21555
20-21666
20-21777
20-21888
20-21999
20-21101010
20-21111111
20-21121212
20-21131313

 

I thought of your suggestion but the end-user needs the slicer to look like the screenshot from my original post plus I also have YTD calculations so not sure if that would have an impact. Excuse my silly questions but why does it work well for Year 19-20 but not for 20-21? For some reason I can't choose anything else other than many to many relationship. I also had both directional before but changing it to single direction doesn't seem to do anything.

Will have to recreate to know. Give me some time. You could still have the slicer look like that, you would just create columns in your new table that split the year and period back out.

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@PowerBI-Newbie - I am missing some info to recreate this, Actual-LD and Late Delivery columns?

 

SIP Actual = (sum(SIP_Activities[Actual-LD]) + sum(SIP_Activities[Late Delivery]))

 

What are those in the data you presented?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Apologies @Greg_Deckler , here's the complete dataset:

 

YearPeriodPlannedActual-LDLate Delivery
19-20199 
19-2021515 
19-2031617 
19-2041415 
19-2051210 
19-2061313 
19-2071013 
19-2081113 
19-20999 
19-20101213 
19-201199 
19-20121012 
19-201393 
20-21111 
20-21222 
20-21333 
20-21444 
20-21555 
20-21666 
20-21777 
20-21888 
20-21999 
20-21101010 
20-21111111 
20-21121212 
20-21131313 

 

I must've missed Late Delivery out since it's an empty column at the moment but I guess in the future that might change, and didn't type the Actual-LD column properly.

OK, yeah, just switching this from many to many to one to one fixes everything. I couldn't get the many to many work for either year.

 

See PBIX attached.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you very much @Greg_Deckler , that worked really well.

 

May I ask, how can I now filter the table such that when I select Period 2 for a particular fiscal year then it displays Periods 1-2 data for Planned or Actual-LD, and when I select Period 3 then it displays Periods 1-3 data?

Oh, for that you need what I call a Complex Selector. I really have to post this out to the Quick Measures Gallery. It is basically the same concept as Inverse Selector.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Inverse-Selector/m-p/648290#M325

 

You create a measure that returns 1 if you want to show something and 0 otherwise and then filter on that measure. I am attaching an example.

 

This one is coming up all the time lately! I think 3 times today!!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for your response @Greg_Deckler .

 

I had a look at the link and it mentions something about making sure there are no relationships but my slicers Period (1-13) and Fiscal Year (19-20, 20-21, etc.) have relationships with other tables. I also had a look at the file you attached and I was really confused (I'm noobie in Power BI).

 

So how do I tell it to display all Actual figures from Periods 1 to 3 if the user selects Period 3? I'll attached the pbix file once I remove all sensitive information so that you can see what I mean.

All I can really say is that you are going to need to use ALL or ALLSELECTED somewhere to get rid of the filter from your slicer. Can work with relationships between things but generally makes it harder.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

I've created the .pbix file to attach but unable to do so for some reason.

I'm trying what you said but it's not working for some reason.

 

You will need to share it using OneDrive or Box or some other file sharing service and post link here.

@PowerBI-Newbie

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

OK, so regarding your request @PowerBI-Newbie - so am I missing something here or is:

 

May I ask, how can I now filter the table such that when I select Period 2 for a particular fiscal year then it displays Periods 1-2 data for Planned or Actual-LD, and when I select Period 3 then it displays Periods 1-3 data?

 

Soooo...isn't that just your YTD measure?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler , the YTD measure is the cumulative sum up to and including the Period that the user has selected.

 

What I'm after is the figures of the Periods 1 to User Selection to be displayed as a line chart (under Trend in the visuals). So if Period 3 is selected then I'll see 3 points on the line chart.

A bit tricky, but a disconnected table trick and this measure later and I think I got it. PBIX is attached:

SIP Actual Line Chart = 
    VAR __Year = MAX('SIP_Activities'[Year])
    VAR __Period = MAX('SIP_Activities'[Period]) + 0
    VAR __LinePeriod = MAX('Periods'[Period]) + 0
    VAR __Table = FILTER(ALL(SIP_Activities),[Year] = __Year && [Period]+0 <= __Period)
    VAR __Table1 = FILTER(__Table,[Period]+0 = __LinePeriod)
RETURN
    SUMX(__Table1,[Actual-LD]) + SUMX(__Table1,[Late Delivery])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Than you very much @Greg_Deckler . I copied and pasted your Measure into my dashboard and for some strange reason I get a VAR error message on my work Power BI Desktop (see error message):

Power BI Report-Dashboard-YTD Trend Lines VAR Error Message.PNG

 

In fact, I can't open the file as it's apparently a newer version. Having said that, I can open it on my personal laptop without any issues and can see your solution without any VAR error message. I checked the work version number and it's 2.73.5586.1101 (September 2019) while ony my personal laptop it's 2.80.5803.1061 (April 2020), could this be the issue? Is there a workaround?

You are missing a paren ) @PowerBI-Newbie 

 

VAR __LinePeriod = MAX('Periods'[Period]) + 0

You have:

VAR __LinePeriod = MAX('Periods'[Period] + 0

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.