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
Anonymous
Not applicable

cross tab output with calculated measure using sameperiod last year

hello,

newb here so i am probably missing some terminology that would make finding the answer to this much easier (apologies up front)

i have a report i am trying to create with rows and columns of calculated counts.

 

each row should have 4 columns. currently i have created a new measure for each column. so it should look like

 

Row 1: first-measure name: 

(Column 1) distinct Count 

(Column 2) distinct count using sameperiodlastyear    

(Column 3) the variance as first measure - second measure   

 (Column 4) the trend first measure / second measure

 

these measures seem to work when i put them in a bar chart etc unless... i try to show them per month. once i add the YEAR_MONTH column from our date dimension the SAMEPERIODLASTYEAR calculation no longer seems to work. So i am guessing i should use something other than sameperiodlastyear.

any help is appreciated.

adding the dax i am using... if i put both in a matrix with the year_month the first distinct count works fine. but if i add the prev year i only get the total for the time period selected in the slicer. it won't give the sub totals at each of the months

 

Cur_year_count = CALCULATE(DISTINCTCOUNT(MAIN_FACT[ID_CUSTOMER_VISIT]), (MAIN_FACT[ID_CUSTOMER_VISIT] <>BLANK()) + 0)

 

Prev_year_count =  CALCULATE(DISTINCTCOUNT(MAIN_FACT[ID_CUSTOMER_VISIT]), (MAIN_FACT[ID_CUSTOMER_VISIT] <>BLANK()) + 0, SAMEPERIODLASTYEAR(MAIN_FACT[ORIG_SERVICE_DATE]))

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

For SAMEPERIODLASTYEAR Function is a Time-intelligence function. So you'd better use a dim date table for calculation as below:

Step1:

Create a dim date table, eg.

Date = CALENDARAUTO()
Step2:
Create the measure as below:
Prev_year_count =  CALCULATE(DISTINCTCOUNT(MAIN_FACT[ID_CUSTOMER_VISIT]), (MAIN_FACT[ID_CUSTOMER_VISIT] <>BLANK()) + 0, 
SAMEPERIODLASTYEAR('Date'[Date]))
Step3:
Use date field from dim date table instead of data table to create visuals.
 
here is my sample example:
6.JPG
and here is my sample pbix file, please try it.
 
Best Regards,
Lin
 

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

For SAMEPERIODLASTYEAR Function is a Time-intelligence function. So you'd better use a dim date table for calculation as below:

Step1:

Create a dim date table, eg.

Date = CALENDARAUTO()
Step2:
Create the measure as below:
Prev_year_count =  CALCULATE(DISTINCTCOUNT(MAIN_FACT[ID_CUSTOMER_VISIT]), (MAIN_FACT[ID_CUSTOMER_VISIT] <>BLANK()) + 0, 
SAMEPERIODLASTYEAR('Date'[Date]))
Step3:
Use date field from dim date table instead of data table to create visuals.
 
here is my sample example:
6.JPG
and here is my sample pbix file, please try it.
 
Best Regards,
Lin
 

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.