Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi,
I have below data in system which is in Discrete month.
Jan | Feb | Mar | |
Sales | 10 | 11 | 14 |
Profit | 5 | 6 | 6 |
My requirement is to create a slicer of Discrete & YTD and switch between Discrete and YTD data based on that.
Solved! Go to Solution.
Hi @rajibmahmud,
Regarding the sample data you provided, we need to Unpivot columns "Jan","Feb","Mar" to one column like below in Query Editor.
Then create a column to return month value:
MonthNum = SWITCH('Table1'[Month],"Jan",1,"Feb",2,"Mar",3)
Create a new table which store two values "Discrete" and "YTD". Then create a measure:
FilteredBySlicer = IF(LASTNONBLANK('Table2'[Column1],"")="Discrete",SUM(Table1[Value]),IF(LASTNONBLANK('Table2'[Column1],"")="YTD",CALCULATE(SUM(Table1[Value]),FILTER(ALL('Table1'),'Table1'[Category]=MAX('Table1'[Category]) && 'Table1'[MonthNum]<=MAX('Table1'[MonthNum]))),0))
For details, see attchached pbix file.
Best Regards,
Qiuyun Yu
Hi @rajibmahmud,
Nope. Please go through detail information about LASTNONBLANK Function (DAX) and HASONEVALUE Function (DAX).
Best Regards,
Qiuyun Yu
Hi @rajibmahmud,
Regarding the sample data you provided, we need to Unpivot columns "Jan","Feb","Mar" to one column like below in Query Editor.
Then create a column to return month value:
MonthNum = SWITCH('Table1'[Month],"Jan",1,"Feb",2,"Mar",3)
Create a new table which store two values "Discrete" and "YTD". Then create a measure:
FilteredBySlicer = IF(LASTNONBLANK('Table2'[Column1],"")="Discrete",SUM(Table1[Value]),IF(LASTNONBLANK('Table2'[Column1],"")="YTD",CALCULATE(SUM(Table1[Value]),FILTER(ALL('Table1'),'Table1'[Category]=MAX('Table1'[Category]) && 'Table1'[MonthNum]<=MAX('Table1'[MonthNum]))),0))
For details, see attchached pbix file.
Best Regards,
Qiuyun Yu
Thanks alot.
I never used LASTNONBLANK before, can it be replaced with Hasonevalue?
Hi @rajibmahmud,
Nope. Please go through detail information about LASTNONBLANK Function (DAX) and HASONEVALUE Function (DAX).
Best Regards,
Qiuyun Yu
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
81 | |
79 | |
58 | |
35 | |
32 |
User | Count |
---|---|
99 | |
59 | |
56 | |
46 | |
40 |