cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
elliottriley
Frequent Visitor

Creating dynamic measures using a slicer to change date values

We have a fact table that shows one row per visit.  Against each visit is a date, visitID, an outletID, outletname and some other numbers.

 

What we want to do is use a slicer to specify a date range using the date in the table as the source.  We then want to have a measure that dynamically calculates the latest date (based within the slicer selection) by outletID within that table and show only the latest outletID record within the date chosen in the slicer and then add on two other measure columns calculated from column1 and column 2.

 

 

Fact table as below

VisitID   Date            OutletID  OutletName   Column1  Column2

123        01/01/2018   65            Name A             1             1

143        20/01/2018   65            Name A             0             1

145        21/01/2018   34            Name B             1             2 

165        02/02/2018   65            Name A             0             1

171        15/02/2018   34            Name B             1             1

 

 

Can anyone help with the DAX as what we have tried seems to take ages to run on desktop and only runs if the date range is really narrow.  Then when published to the service it errors and says that it exceeds the resources.  There are 500k rows in the fact table and it will grow over time.  If we needed to we could restrict the date range chosen in the slicer if that is possible?

 

Is there a best practice way of doing this?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

This may be what you have already but if you have a table with OutletID in it then you could calculate the last date as follows:

 

Measure = 
VAR __maxDate = MAX([Date])
RETURN
MAXX(FILTER('Table',[Date]<=__maxDate),[Date])

The thought here is that if you have OutletID in the table, then your fact table is already constrained by OutletID for each row in the table. So you just need to find the MAXX of the Date for that already filtered (context) table.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

This may be what you have already but if you have a table with OutletID in it then you could calculate the last date as follows:

 

Measure = 
VAR __maxDate = MAX([Date])
RETURN
MAXX(FILTER('Table',[Date]<=__maxDate),[Date])

The thought here is that if you have OutletID in the table, then your fact table is already constrained by OutletID for each row in the table. So you just need to find the MAXX of the Date for that already filtered (context) table.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors