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
unais
Helper V
Helper V

Same Period Last Year Not Working With Filter

Dears,

Please advise below  DAX  with Sameperiodlast year not working..

 

SalaryWithCC(WithoutWPS) Last Year = CALCULATE(SUM(ZFAGLFLEXA_FI_DOC[NEWHSL]) ,FILTER(ZFAGLFLEXA_FI_DOC,ZFAGLFLEXA_FI_DOC[RCNTR] <> "" ),FILTER(GLMapping,GLMapping[GLGroup_Index]="3"),FILTER(ZCEPCT_PRFT_TXT,ZCEPCT_PRFT_TXT[INCGRP1]="INCGRP1"),SAMEPERIODLASTYEAR('Calendar'[Date]) )
 
Whereas without the same period last year it's working.
 
SalaryWithCC(WithoutWPS) Last Year = CALCULATE(SUM(ZFAGLFLEXA_FI_DOC[NEWHSL]) ,FILTER(ZFAGLFLEXA_FI_DOC,ZFAGLFLEXA_FI_DOC[RCNTR] <> "" ),FILTER(GLMapping,GLMapping[GLGroup_Index]="3"),FILTER(ZCEPCT_PRFT_TXT,ZCEPCT_PRFT_TXT[INCGRP1]="INCGRP1") )

 

Also if I remove Filter : 

FILTER(ZFAGLFLEXA_FI_DOC,ZFAGLFLEXA_FI_DOC[RCNTR] <> "" )
and with SAMEPERIODLAST YEAR it's working
 
 
SalaryWithCC(WithoutWPS) Last Year = CALCULATE(SUM(ZFAGLFLEXA_FI_DOC[NEWHSL]) ,FILTER(GLMapping,GLMapping[GLGroup_Index]="3"),FILTER(ZCEPCT_PRFT_TXT,ZCEPCT_PRFT_TXT[INCGRP1]="INCGRP1"),SAMEPERIODLASTYEAR('Calendar'[Date]) )
 
 so what's wrong with the query  please advise

 

1 ACCEPTED SOLUTION
FarhanAhmed
Community Champion
Community Champion

I think best thing is to do is create 2 filters

 

- One with your actual measures with Filter

SalaryWithCC(WithoutWPS)  = CALCULATE(SUM(ZFAGLFLEXA_FI_DOC[NEWHSL]) ,FILTER(ZFAGLFLEXA_FI_DOC,ZFAGLFLEXA_FI_DOC[RCNTR] <> "" ),FILTER(GLMapping,GLMapping[GLGroup_Index]="3"),FILTER(ZCEPCT_PRFT_TXT,ZCEPCT_PRFT_TXT[INCGRP1]="INCGRP1") )

 

- After that you should create Last Year Measure

 

SalaryWithCC(WithoutWPS) Last Year = CALCULATE( SalaryWithCC(WithoutWPS), SAMEPERIODLASTYEAR (Calendar[Date]))

 

Make sure that your calendar is marked as "Date Table"

Mark As Date Table.png







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

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Icey
Community Support
Community Support

Hi @unais ,

 

It's best to share us your .pbix file for test. Please remove sensitive information and unnecessary visuals. It is suggested to upload your file to OneDrive for Business and then paste the link here.

 

 

 

Best Regards,

Icey

amitchandak
Super User
Super User

@unais , use

not(isblank(ZFAGLFLEXA_FI_DOC[RCNTR] )) for ZFAGLFLEXA_FI_DOC[RCNTR] <> ""

 

Also, make sure your calendar table is marked as date table.

Example of other ways

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

refer

https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

I had created Two Mesure 

like below

 

 

GLTotalLR = CALCULATE(SUM(ZFAGLFLEXA_FI_DOC[NEWHSL]),DATESYTD(DATEADD('Calendar'[Date],-1,YEAR),"12/31"))
 
SalaryWithCC(WithoutWPS) Last Year = CALCULATE([GLTotalLR],FILTER(ZFAGLFLEXA_FI_DOC,NOT(ISBLANK(ZFAGLFLEXA_FI_DOC[RCNTR])) ),FILTER(GLMapping,GLMapping[GLGroup_Index]="3"),FILTER(ZCEPCT_PRFT_TXT,ZCEPCT_PRFT_TXT[INCGRP1]="INCGRP1"))
but didn't work ...
 
FarhanAhmed
Community Champion
Community Champion

I think best thing is to do is create 2 filters

 

- One with your actual measures with Filter

SalaryWithCC(WithoutWPS)  = CALCULATE(SUM(ZFAGLFLEXA_FI_DOC[NEWHSL]) ,FILTER(ZFAGLFLEXA_FI_DOC,ZFAGLFLEXA_FI_DOC[RCNTR] <> "" ),FILTER(GLMapping,GLMapping[GLGroup_Index]="3"),FILTER(ZCEPCT_PRFT_TXT,ZCEPCT_PRFT_TXT[INCGRP1]="INCGRP1") )

 

- After that you should create Last Year Measure

 

SalaryWithCC(WithoutWPS) Last Year = CALCULATE( SalaryWithCC(WithoutWPS), SAMEPERIODLASTYEAR (Calendar[Date]))

 

Make sure that your calendar is marked as "Date Table"

Mark As Date Table.png







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

Proud to be a Super User!




vanessafvg
Super User
Super User

maybe it would be better to use if(isblank(field) rather than <> ""




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

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!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

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.