cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

Resolver I

## 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 = ?

3 REPLIES 3
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.

Proud to be a Super User!

Resolver I

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:

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.

Super User

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

Proud to be a Super User!

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors