Forum Discussion
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
- parry2kSuper 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 - parry2kSuper 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 - ExcelMonkeImpactful Individual
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)) - noobtopowerbiFrequent 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])-1Returncalculate(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- ExcelMonkeImpactful Individual
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) )
- parry2kSuper 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.
- AnonymousNot applicable
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 🙂- ExcelMonkeImpactful Individual
Just remember, it would be best practice to have your date table only contain unique values.