Forum Discussion
Matrix show relevant months without filters
Hello,
I have a bit of a problem which I'm confused by. I have data from this year and last year. I want to show the data in a matrix where Months are in a column, also only the last year. So basically, if it's July today, show only months up to July 2020.
I have a measure that goes like this:
DimDate,
)
This should read : Filter the DimDate table where the Maximum month is July and Max Year is 2020.
When I try to hard code the year, it works although it should be the same thing.
DimDate,
)
What am I missing here? Why doesn't my initial CurrentYear variable work in this context although it gives the sam result?
Thanks.
Hi Anonymous ,
The measure changes according to the content of the current line.
Try to calculate "MAX" like this:
measure= var max_year = CALCULATE(MAX('Table'[Date].[Year]),ALL('Table')) var max_month = CALCULATE(MAX('Table'[Date].[MonthNo]),FILTER(ALL('Table'),'Table'[Date].[Year]=max_year)) return CALCULATE([Sales Value],FILTER( DimDate, MONTH(DimDate[Date]) <= max_month && YEAR(DimDate[Date]) = max_year ) )Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
5 Replies
- amitchandak
Super User
Anonymous , do you need YTD?
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31")) Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31")) This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31")) Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31")) Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31")) Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))refer: https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
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/
See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184
Appreciate your Kudos.- AnonymousNot applicable
Hi, thank you for your answer but it's not what I am looking for.
The problem is that my matrix is not filtering the year. It's showing this (2020 means that the data is from 2020, 2019 that it is from 2019):jan feb march april may june july august september october november december Monthly sales 2020 2020 2020 2020 2020 2020 2020 2019 2019 2019 2019 2019 and I need this:
jan feb march april may june july Monthly sales 2020 2020 2020 2020 2020 2020 2020
I can adjust this with filters but would rather have a measure.- V-lianl-msft
Community Support
Hi Anonymous ,
The measure changes according to the content of the current line.
Try to calculate "MAX" like this:
measure= var max_year = CALCULATE(MAX('Table'[Date].[Year]),ALL('Table')) var max_month = CALCULATE(MAX('Table'[Date].[MonthNo]),FILTER(ALL('Table'),'Table'[Date].[Year]=max_year)) return CALCULATE([Sales Value],FILTER( DimDate, MONTH(DimDate[Date]) <= max_month && YEAR(DimDate[Date]) = max_year ) )Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.