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
Jeet_Analytics
Regular Visitor

Last 12 Months based on Date slicer selection- and sales against them

Hi Team,

 

The requirement is to show the last 12 months of data in a visual, based on the date slicer selection.

 

Example:

 

i) If Date Selected in the slicer is: 15/11/2021

then the visual shall be showing the data of month range 15/11/2020 to 15/11/2021.

 

ii) If no Date is selected in the slicer, then the visual shall be showing the data of last 12 months from the max date available in the model.

 

My Approach:

 

When I create a measure to check if the date from which last 12 months is to be calculated as below, it works really fine:

 

DateFilter =
IF(
HASONEVALUE(Dates[Date]),
SELECTEDVALUE(Dates[Date]),
MAX(Dates[Date])
)

 

But when I try to create a calculated table as below (using the same logic) :

 

Date-New-TEST =
var DateFilter =
IF(
HASONEVALUE(Dates[Date]),
SELECTEDVALUE(Dates[Date]),
MAX(Dates[Date])
)

RETURN
CALENDAR(
DATE(Year(DateFilter),
MONTH(DateFilter)-12,
DAY(DateFilter)
)
,
DateFilter)

 

the Dax formula always considers the Else statement of the DAX written in the IF() section. i.e. somehow hasonevalue() is always returning false in the calculated table formula even when only one date value is selected. But the same logic works fine when I create a measure and check the selected value with the logic of hasonevalue() as I mentioned above.

 

Do we have any idea what could be the possible reason behind this?    

 

Thanks,

 

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @Jeet_Analytics,

Current power bi does not support creating dynamic calculated column/table based on filter/slicer selection, they are working on different data levels and you can't use child level to affect its parent.

For your scenario, I'd like to suggest you use query parameter instead, you can convert it to the query table. Then you can use Dax calculate table expression to extract that parameter and use it in the calculated table.

Notice: the data level of power bi.

Database(external) -> query table(query, custom function, query parameters) -> data model table(table, calculate column/table) -> data view with virtual tables(measure, visual, filter, slicer)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @Jeet_Analytics,

Current power bi does not support creating dynamic calculated column/table based on filter/slicer selection, they are working on different data levels and you can't use child level to affect its parent.

For your scenario, I'd like to suggest you use query parameter instead, you can convert it to the query table. Then you can use Dax calculate table expression to extract that parameter and use it in the calculated table.

Notice: the data level of power bi.

Database(external) -> query table(query, custom function, query parameters) -> data model table(table, calculate column/table) -> data view with virtual tables(measure, visual, filter, slicer)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@Jeet_Analytics , If you select on date and need data for more that day or range, you need an independent date table 

 

// Independent Date table - Date1 and Joined Table Date - Last 12 Month
measure =
var _max = maxx(allselected('Date1'),'Date1'[Date]) // Use Date(2012,01,01)
var _min = Date(year(_max) -1, Month(_max), Day(_max))
return
CALCULATE(SUM(Sales[Sales Amount]),filter(Date, Date[Date]>=_min && Date[Date] <=_max ))

 

refer

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

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.