Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
Hi guys, I have 2 tables - Date_ref and Asset. Date_ref is date table. Asset have monthly total asset value in which there are data from Jan 2021 - Aug 2023. I used a slider by year, if a year is selected, the monthly total asset values are displayed.
When select 2023 in slider, it displays Jan-Aug
I want to show data of current year (2023) as default when there is no tile in slicer selected, so i try writing the DAX below:
Total Asset =
VAR max_year = CALCULATE(MAX(Dates_ref[Year]))
VAR asset = CALCULATE(SUM(Asset[Value]), Asset[Attribute] = "Total Asset")
VAR default_asset = CALCULATE(SUM(Asset[Value]), Asset[Attribute] = "Total Asset", Dates_ref[Year] = max_year)
Return IF(NOT(ISFILTERED(Dates_ref)), default_asset, asset)
However the output is not as expected
When I do not select any tile in slider, output display incorrect values, it also display 12 months while 2023 just have Jan - Aug.
How to show data of current year (2023) as default, Is there any problem with IF or ISFILTERED?
Thank you in advance!
Solved! Go to Solution.
I would suggest using SELECTEDVALUE instead of ISFILTERED, could you please try below?
Total Asset =
VAR _selectedYear = SELECTEDVALUE(Dates_ref[Year])
VAR max_year = CALCULATE(MAX(Dates_ref[Year]))
VAR asset = CALCULATE(SUM(Asset[Value]), Asset[Attribute] = "Total Asset")
VAR default_asset = CALCULATE(SUM(Asset[Value]), Asset[Attribute] = "Total Asset", Dates_ref[Year] = max_year)
Return
IF(NOT(_selectedYear), default_asset, asset)
I would suggest using SELECTEDVALUE instead of ISFILTERED, could you please try below?
Total Asset =
VAR _selectedYear = SELECTEDVALUE(Dates_ref[Year])
VAR max_year = CALCULATE(MAX(Dates_ref[Year]))
VAR asset = CALCULATE(SUM(Asset[Value]), Asset[Attribute] = "Total Asset")
VAR default_asset = CALCULATE(SUM(Asset[Value]), Asset[Attribute] = "Total Asset", Dates_ref[Year] = max_year)
Return
IF(NOT(_selectedYear), default_asset, asset)
It's worked, thank you so much.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
19 | |
12 | |
10 | |
9 | |
9 |
User | Count |
---|---|
17 | |
15 | |
12 | |
10 | |
9 |