Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
H3nning
Helper V
Helper V

Previous Period as single Value

Hi,

 

Im experimenting with SCD2 data and I have a problem with a time intelligence related calculation. To keep it simple Id rather not explain the whole complexity of the context.

 

I have a table with dates. Pretty much self explanatory, every day in one row. There are no relations to other tables.

 

In a calculation i need to get the dynamic minimum of the date table in a hierarchy. 

For example i build a column chart and bring the date on the x-Axis. Then dependend on the drill down level I built a variable with the minimum date:

VAR MINDATE = MIN(Date[Date])

 

So if Im on Month level the MINDATE in the August Slice would be "2023-08-01".

 

Now I need a second Date which represents the minimum of the previous period depending on the drill down level. So if im on month the PREVDATE in the August Slice would be "2023-07-01".

 

And now important:

if I drill down to days the values for the 1st of August would be

MINDATE=2023-08-01

PREVDATE=2023-07-31 <- so now it is not one month before, but one day, because of day drill-level!

 

If Im on the quarter Level it should also adapt. Values for Q3:

MINDATE = 2023-07-01

PREVDATE = 2023-04-01

 

Same with years, i think the pattern is clear now.

 

Any ideas how to achieve this. Perfect would be how to calculate a variable in a measure. VAR PREVDATE = ?

 

Thanks in advance 🙂 

3 REPLIES 3
some_bih
Super User
Super User

Hi @H3nning as you are on beginning of your project, I suggest to check link about different date calculation in DAX.

Find your scenario, it could be MTD, PMC, PM some other concerning months. Benefit of this solution is that in future you can easly adopt rest of time intelligence calculation which currently you do not need. 

Did I answer correctly? Kudos appreciate / accept solution.

Link: https://www.daxpatterns.com/standard-time-related-calculations/ 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi, thank you, but I couldn't find a solution there. I tried two approaches. With ISINSCOPE it seems it does not work with an automatic hierarchy. My resultset is always empty. I used

SWITCH(TRUE,

   ISINSCOPE(Date.Day), ~Calculation for day level~

   ,ISINSCOPE(Date.Month), ~Calculation for month level~

   ,ISINSCOPE(Date.Quarter), ~Calculation for quarter level~

   ,ISINSCOPE(Date.Year), ~Calculation for year level~

 

The result is always empty, although i tested the calculation for month level and it is correct. But even on month level it looks like this:

H3nning_0-1692597216256.png

 

 

The other thing I thought about is PARALLELPERIOD, but the issue with that is, that it returns a table of dates. But I need a single value to compare it to my SCD2 data. MIN(PARALLELPERIOD()) is also not possible, because MIN requires a column, not a table.

Hi @H3nning I usually find my scenario on link from SQLBI.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.