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
noobtopowerbi
Frequent Visitor

compare with count previous year

I have a table1 containing customerid, month, presenceboolean. I have a calendartable containing date,month,year.

Now I want to visualize a table with columns year, distinctcount customerid and distinctcount customerid previous year

I created two measures:

for current year : this_year= calculate(distinctcount(table1[customerid),filter(presenceboolean = 1))

for previous year :

  previous_year = calculate(distinctcount(table1[customerid),sameperiodlastyear('calendartable'[date],filter(presenceboolean = 1))

 

the month field in table1 is formatted dd-mm-yyyy and is linked to the datefield in the calendertable

the dax formula for previous year does not give any result. I used the function previousyear to, but that did not give results either

 

What is wrong with my formula. Google did not help 🙂

 

8 REPLIES 8
parry2k
Super User
Super User

@noobtopowerbi again pointing out this playlist which has all the time intelligence functions talked in detail along with how to compare with the previous year:

Mark date dimension as a date table - why and how?
Time Intelligence Playlist

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@noobtopowerbi I would be very careful using this approach because it is not the best practice and will hit the performance issues on the larger data table. If you want to do the things right way, following best practices, add the date table and use that for all-time intelligence-related measures. The choice is yours. Do it right, or have a short-term solution.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thank you for your answer. I tried the same using a calendar table containing year,month and year_month. Lin ked by year_month, but that did not help to.
I will dive into the suggestions on date topics. Sometime I will solve this 🙂

Just remember, it would be best practice to have your date table only contain unique values.

noobtopowerbi
Frequent Visitor

I must be doing something wrong, I get the right results for previous year but not for the actual year.
As I cannot add a pbix file to my posts I will give as much informations as possible :

This is the measure for current year :

presence this year = calculate(DISTINCTCOUNT('Table'[employee]),
        Filter(all('Table'),'Table'[month]= 9),
        'Table'[presence]=1
)
For previous year: 
presence previous year =
 VAR Previous_Year = max('Table'[year])-1
 Return
 calculate(DISTINCTCOUNT('Table'[employee]),

        Filter(all('Table'),'Table'[month]= 9),'Table'[year]=Previous_Year,
        Filter(all('Table'),'Table'[presence]=1))

Now I get for the current year a count of all employees while not every value for presence =1 in month 9
noobtopowerbi_0-1702565200128.pngnoobtopowerbi_1-1702565233944.png

 

 

 
 

Hi there, you may have a parentheses misplaced 🙂 
Try:

presence this year = calculate(DISTINCTCOUNT('Table'[employee]),
        Filter(all('Table'),'Table'[month]= 9,
        'Table'[presence]=1)
)
ExcelMonke
Resolver III
Resolver III

Hello, 
Based off your description, try the following:

 

Previous Year =
VAR Previous_Y = Year(MAX(DateTable[Date]))-1

Return
CALCULATE(COUNT(Table1[CustomerID]),FILTER(ALL(DateTable),Year(DateTable[Date])=Previous_Y))
parry2k
Super User
Super User

@noobtopowerbi the month column in the table1, does it contain date value or month value? Can you share sample data? In the meantime, check out these related videos on my channel which have in-depth explanation of all time intelligence functions:

 

Importance of Date Dimension
Mark date dimension as a date table - why and how?
Time Intelligence Playlist

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.