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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors