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
Anonymous
Not applicable

Filtering results on X Axis

Hi,

 

New to PowerBI so apologies if this should be obvious.

 

If I have the following data:

Fiscal YQ table

 

YQrownum
2020 Q 4        1
2020 Q 3        2
2020 Q 2        3
2020 Q 1        4
2019 Q 4        5
2019 Q 3        6
2019 Q 2        7
2019 Q 1        8

 

Then another table

YQRepNet Amount USD
2020 Q 4John Smith200
2020 Q 3Jane Doe500
2019 Q 4John Smith400

 

And I have a slicer on the YQ item, how would I ensure that:

A stacked bar chart only shows x numbers of items on the x axis.  Specifically, I wanted to show a max of last 4 quarters in the past if nothing is filtered (I have multiple years of data, the chart gets crowded, but I don't want to filter this information out as people may want to review items 3 years in the past).

 

I had created a measure:

QuarterSelectBounds = ((CALCULATE(MIN('AnalysisFiscalYearQuarterSort'[rownum]),ALLSELECTED(AnalysisFiscalYearQuarterSort[rownum]))+3))
 
and then another measure
Net Amount USD QuarterSelectBounded = IF(MIN('AnalysisFiscalYearQuarterSort'[rownum]) <= [QuarterSelectBounds], sum('Bookings'[Net Amount USD]), BLANK())
 
This works great, but only if I am using rownum on the x axis.  As soon as I swap it out to the YQ value, the min is applied on the line level.  I have done a lot of reading and feel like I might need to create some sort of disconnected table, but I'm a little lost at this point.  Any help?
 
Thanks
1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

If you want this to work for all YQ then you need to use YQ in the ALLSELECTED:

QuarterSelectBounds = ((CALCULATE(MIN('AnalysisFiscalYearQuarterSort'[rownum]),ALLSELECTED(AnalysisFiscalYearQuarterSort[YQ]))+3))

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Create a common qtr year table, join with both table . Create a Qtr year rank in that on year qtr

 

new column
Qtr Rank = RANKX(all('Date'),'Date'[Qtr Start date],,ASC,Dense)

 

measure
This Qtr = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])))
Last Qtr = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])-1))

 

last 4 Qtr = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'), 'Date'[Qtr Rank]>=max('Date'[Qtr Rank])-4 && 'Date'[Qtr Rank]<=max('Date'[Qtr Rank])))

AllisonKennedy
Super User
Super User

If you want this to work for all YQ then you need to use YQ in the ALLSELECTED:

QuarterSelectBounds = ((CALCULATE(MIN('AnalysisFiscalYearQuarterSort'[rownum]),ALLSELECTED(AnalysisFiscalYearQuarterSort[YQ]))+3))

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.

Top Solution Authors