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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
rpiboy_1
Helper V
Helper V

Previous Period Pattern, inconsistent results

I have two fact tables joined to the same (well formed) date Table, both on 'Date'[Date].

 

In fact table 1 I'm using the following measure to calculate previous period for a sumed value:

 

Previous Period Logins = 
SWITCH(
    TRUE(),
    ISINSCOPE( 'Date'[Date] ),
        CALCULATE( [Logins (sum)], DATEADD( 'Date'[Date], -1, DAY )),
    ISINSCOPE( 'Date'[Fiscal Month] ),
        CALCULATE( [Logins (sum)], DATEADD( 'Date'[Date], -1, MONTH )),
    ISINSCOPE( 'Date'[Fiscal Quarter] ),
        CALCULATE( [Logins (sum)], DATEADD( 'Date'[Date], -1, QUARTER )),
    ISINSCOPE( 'Date'[Fiscal Year] ),
        CALCULATE( [Logins (sum)], DATEADD( 'Date'[Date], -1, YEAR ))
)

 

I applied the same pattern to fact table 2, again a SUM on a value, and instead of returning the previous period, it returns the same value as the 'current' period. I'm super confused as I've checked backwards and forwards and there are no 'differences' other than a different fact table and different facts.

 

Design Area Avg Previous Period = 
VAR _area = SUM('Monthly Project Data'[Design Area Avg])
VAR _result =
    SWITCH(
        TRUE(),
        ISINSCOPE( 'Date'[Date] ),
            CALCULATE( _area , DATEADD( 'Date'[Date], -1, DAY )),
        ISINSCOPE( 'Date'[Fiscal Month] ),
            CALCULATE( _area , DATEADD( 'Date'[Date], -1, MONTH )),
        ISINSCOPE( 'Date'[Fiscal Quarter] ),
            CALCULATE( _area , DATEADD( 'Date'[Date], -1, QUARTER )),
        ISINSCOPE( 'Date'[Fiscal Year] ),
            CALCULATE( _area , DATEADD( 'Date'[Date], -1, YEAR ))
    )
RETURN
_result

 

I guess the only other thing worth noting is that both facts have monthly granularity, not daily, but that should not matter, as I'm not trying to visualize the data at daily granularity anyway.

Looking for advice on what else I should be considering as to why I'm getting inconsistent results. What am I possibly missing or forgetting about?

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@rpiboy_1 Variables (VAR) despite their name are constants and once calculated remain the same value regardless of anything you might try to do. So, that's the reason for the results you are getting.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @rpiboy_1 ,

 

I’d like to acknowledge the valuable input provided by Greg_Deckler . Their initial ideas were instrumental in guiding my approach. However, I noticed that further details were needed to fully understand the issue. 

 

You can refer to my example and make appropriate changes to your measure.

vkaiyuemsft_0-1724823398630.png

 

Measure = 
VAR _result = 
    SWITCH(
        TRUE(),
        ISINSCOPE( 'Date'[Date].[Day] ),
            CALCULATE( SUM('financials'[ Sales]), DATEADD( 'Date'[Date], -1, DAY )),
        ISINSCOPE( 'Date'[Date].[Month] ),
            CALCULATE( SUM('financials'[ Sales]) , DATEADD( 'Date'[Date], -1, MONTH )),
        ISINSCOPE( 'Date'[Date].[Quarter] ),
            CALCULATE( SUM('financials'[ Sales]) , DATEADD( 'Date'[Date], -1, QUARTER )),
        ISINSCOPE( 'Date'[Date].[Year]),
            CALCULATE( SUM('financials'[ Sales]) , DATEADD( 'Date'[Date], -1, YEAR ))
    )
RETURN
_result

vkaiyuemsft_1-1724823432239.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

 

Greg_Deckler
Community Champion
Community Champion

@rpiboy_1 Variables (VAR) despite their name are constants and once calculated remain the same value regardless of anything you might try to do. So, that's the reason for the results you are getting.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Ugh... yeah, I've read that before, but I don't do this work day in and day out, so hard to remember all of the 'details'. Thanks!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.