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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
DebbieE
Community Champion
Community Champion

SAMEPERIODLASTYEAR bringing back current values

This has happened after working on 

Solved: Re: KPIs visuals Running incredibly slowly - Microsoft Fabric Community

 

I have some DAX that is basically doing a distinct count on the person ID

Total People = CALCULATE (
    SUMX (
        VALUES ( 'Dim Person'[Person ID] ),
        1
    ),
    'Fact People'
)

And that gives me my total people

 

I have a date dimension connected by Date Key to Snapshot date key in the fact table. And have another DAX

 

No Pupils Same Period Last Year = CALCULATE (
    SUMX (
        VALUES ( 'Dim Person'[Person ID] ),
        1
    ),
    'Fact People',(SAMEPERIODLASTYEAR('Dim Date'[Date]
)))
 
But this is giving my the current 
 
Year          Period          Total People            No Pupils Same Period Last Year
2022         P2                10000                     10000
2023         P2                10394                      10394
 
Giving these examples of P2 (From the date table which is marked as date)
It should have  10000 for 2023 but its not doing it.
 
I am completely lost at this point again. Have I missed anything?

 

2 ACCEPTED SOLUTIONS
Vallirajap
Resolver III
Resolver III

Hii @DebbieE 

Try this for the above senario,

 

No Pupils Same Period Last Year = CALCULATE ( SUM(Total People),
   SAMEPERIODLASTYEAR('Dim Date'[Date].[Date]
))
 

Did I answer your question?

Mark my post as a solution, this will help others...!

Hit the kudo also,

Thank you

View solution in original post

Ahmedx
Super User
Super User

ply try this

m1 = 
VAR _LastYear = MAX('Dim Date'[Year]) -1
RETURN
CALCULATE (
    SUMX (
        VALUES ( 'Dim Person'[Person ID] ),
        1
    ),
    'Dim Date'[Year] = _LastYear
)

View solution in original post

4 REPLIES 4
DebbieE
Community Champion
Community Champion

 Yep I had done the DAX slightly wrong and resolved it by the above. Thank you

Ahmedx
Super User
Super User

ply try this

m1 = 
VAR _LastYear = MAX('Dim Date'[Year]) -1
RETURN
CALCULATE (
    SUMX (
        VALUES ( 'Dim Person'[Person ID] ),
        1
    ),
    'Dim Date'[Year] = _LastYear
)
Vallirajap
Resolver III
Resolver III

Hii @DebbieE 

Try this for the above senario,

 

No Pupils Same Period Last Year = CALCULATE ( SUM(Total People),
   SAMEPERIODLASTYEAR('Dim Date'[Date].[Date]
))
 

Did I answer your question?

Mark my post as a solution, this will help others...!

Hit the kudo also,

Thank you

I already have this and while it works to get back to the same period last year. It doesnt get me back to the last snapshot

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.