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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ZakEx
Frequent Visitor

Count of invoices This year VS Last year SAMEPERIODLASTYEAR is giving same results HELP PLZ !!

Hi Everyone,

 

I'm trying to count number of invoices of this year and last year i have one table invoice which containes everything but the results i get are the same here is the dax formulas i'm using:

 

This year total invoices = CALCULATE(COUNT(invoice[Type]);invoice[Type] = "Accepted")
Last year total invoices = CALCULATE(COUNT(invoice[Type]);invoice[Type] = "Accepted"; SAMEPERIODLASTYEAR(invoice[date].[Date]))

Results:

invoices.PNG

 

 

 

1 ACCEPTED SOLUTION

Hi @v-jianhe-msft,

 

Thank you very much for this reply i will try your suggestion, but i just want you to know that i solved the problem using Calendar table as follow:

 

Calendar = CALENDAR(MIN(invoice[date]);MAX(invoice[date]))

 

 

Last year total invoices = 
CALCULATE (
COUNT(invoice[Type]),invoice[Type] = "Accepted";
DATESBETWEEN(invoice[date];DATE (YEAR(MIN(invoice[date]))-1; MONTH (MIN(invoice[date])); DAY(MIN(invoice[date])));DATE(YEAR(MAX(invoice[date]))-1; MONTH (MAX(invoice[date]));DAY(MAX(invoice[date])))) 
)

 

 

 

This year total invoices = CALCULATE(COUNT(invoice[Type]),invoice[Type] = "Accepted";DATESBETWEEN(invoice[date];MIN(Calendar[Date]);MAX(Calendar[Date])))

In the date slicer i used the Calendar date and it works perfectly.

 

View solution in original post

3 REPLIES 3
v-jianhe-msft
Resolver II
Resolver II

Hi,

 

How is your table like? Have you, at least, one record for any possible date in the two years? If not, the Intelligence functions can't work as expected.

 

And, if you meet this condition, you could try with:

 

Last year total invoices = CALCULATE(COUNT(invoice[Type]),invoice[Type] = "Accepted", SAMEPERIODLASTYEAR(invoice[date]),ALLEXCEPT(invoice,invoice[date]))

 

1.PNG

 

Best Regards,

Henry

Hi @v-jianhe-msft,

 

I've tried your solution but it shows the same results for all the operators. i've only changed this SAMEPERIODLASTYEAR(invoice[date].[Date])

 

Capture.PNG

CALCULATE(COUNT(invoice[Type]),invoice[Type] = "Accepted", SAMEPERIODLASTYEAR(invoice[date].[Date]),ALLEXCEPT(invoice,invoice[date]))

 

 

 

Hi @v-jianhe-msft,

 

Thank you very much for this reply i will try your suggestion, but i just want you to know that i solved the problem using Calendar table as follow:

 

Calendar = CALENDAR(MIN(invoice[date]);MAX(invoice[date]))

 

 

Last year total invoices = 
CALCULATE (
COUNT(invoice[Type]),invoice[Type] = "Accepted";
DATESBETWEEN(invoice[date];DATE (YEAR(MIN(invoice[date]))-1; MONTH (MIN(invoice[date])); DAY(MIN(invoice[date])));DATE(YEAR(MAX(invoice[date]))-1; MONTH (MAX(invoice[date]));DAY(MAX(invoice[date])))) 
)

 

 

 

This year total invoices = CALCULATE(COUNT(invoice[Type]),invoice[Type] = "Accepted";DATESBETWEEN(invoice[date];MIN(Calendar[Date]);MAX(Calendar[Date])))

In the date slicer i used the Calendar date and it works perfectly.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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