Forum Discussion
Table Visual With Dynamic Dates Across the Top
- Anonymous4 years ago
Hi Anonymous
"If you have different years, you need to update your Date table and measure" This doesn't mean that you need to edit your code everytime you refresh you data. I mean that my sample only has data in one year, so I didn't consider the conditions in different year in my code, you may need to update your code. If you have data between 2021/12 to 2022/01..., you need to update the code.
Here is the new code which can be used in all situations.
New Date table.
Date = VAR _Basic = ADDCOLUMNS ( CALENDARAUTO (), "Year", YEAR ( [Date] ), "Month", MONTH ( [Date] ), "YearMonth", YEAR ( [Date] ) * 100 + MONTH ( [Date] ), "Day", DAY ( [Date] ), "DayName", FORMAT ( [Date], "DDDD" ) ) VAR _ADD1 = ADDCOLUMNS ( _Basic, "DayName First Day", MAXX ( FILTER ( _Basic, [YearMonth] = EARLIER ( [YearMonth] ) && [Day] = 1 ), [DayName] ) ) VAR _ADD2 = ADDCOLUMNS ( _ADD1, "Group", MAXX ( FILTER ( _ADD1, [YearMonth] = EARLIER ( [YearMonth] ) && [DayName] = EARLIER ( [DayName First Day] ) && [Date] <= EARLIER ( [Date] ) ), [Date] ) ) VAR _ADDRANK = ADDCOLUMNS ( _ADD2, "RankYearMonth", RANKX ( _ADD2, [YearMonth],, ASC, DENSE ) ) RETURN _ADDRANKNew Filter Measure.
Measure = VAR _CURRENTYEARMONTH = YEAR(TODAY())*100+MONTH(TODAY()) VAR _CURRENTRANK = CALCULATE(MAX('Date'[RankYearMonth]),FILTER(ALL('Date'),'Date'[YearMonth] = _CURRENTYEARMONTH)) RETURN IF(MAX('Date'[RankYearMonth]) = _CURRENTRANK-1,1,0)You can use this way to filter your visual anytime to show values in last month.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I am not using Excel or Pivot Tables. The data is comming to Power BI from SQL Server via Direct Query, I can send through the data in any structure required since I am writing the queries myself. What I don't know is how to change the data that Power BI recieves into somthing that has dates across the top of the table. So the data table in Power BI could have dates as a column, but how do they become headers on a Power BI table visual? Is it even possible to do that? Thanks, Peter
My bad, I read "matrix visual" the whole time. You can't do that with a table visual, but it is standard functionality of a matrix visual.