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

Measure to calculate sales of prior season only until same day of last year

Hi all,

I'm pretty new of PowerBI, so I'm asking you help for something that may be a basic problem, but I tried to solve it without success.

This is my scenario: I have a sales table like this:

 
DateSame day Of last YearSeasonPrior SeasonQty
06-03-202008-03-2019SS20SS192
07-03-202009-03-2020SS20SS193
08-03-201909-03-2018SS19SS182
09-03-201910-03-2018FW18FW175
10-03-201911-03-2018SS19SS181

 

The user should be able to select a time period based on field "Date" and a sales season, and he wants to see the sold Qty for the selected season vs sold quantity of prior sales season, only considering quantities we sold until the same day of last year.

For instance, if he selects:

  • Time Period: for January 1st 2020 to March 7th 2020
  • Sales Season: SS20

The result shoud be: 

SeasonMeasure Qty Current SeasonMeasure Qty Prior Season
SS2052

 

I was obviously able to create the first measure, it's simple SUM of column Qty, but I don't know how to calculate the second measure, Qty Prior Season.

Basically the measure should filter data based on columns Same day Of last Year and Prior Season: in my example, I have the same day of last year of my selected date is March 9th 2019 and the prior Season is SS19, so the measure should not consider the record with a date after March 9th and a season different from SS19.

Sorry for bother you with this stuff, but, like I said I'm quite new in this magic world.

Thanks for your attention

4 REPLIES 4
Greg_Deckler
Super User
Super User

@Anonymous - There are two basic ways of attacking this problem.

 

One is with the time "intelligence" functions like SAMEPERIODLASTYEAR. You generally wrap your calculation in a CALCULATE and then your filter clause is your time "intelligence" function. You will need a separate, related date table for this to function properly.

https://docs.microsoft.com/en-us/dax/time-intelligence-functions-dax

 

The other way is to just use filters because that's essentially all time "intelligence" functions are. In that case, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks Greg for your feedback, it's very helpful!

I tried to follow your suggestions, so I created this measure for prior year same day value:

 

VAR _MAX_SAME_DAY = MAX ('DTC Cube'[DATE_ID_SAME_DAY])
VAR __TmpTable = CALCULATETABLE('DTC Cube',ALL('DTC Cube'[DATE_ID]))
RETURN SUMX(FILTER(__TmpTable, 'DTC Cube'[DATE_ID]=_MAX_SAME_DAY ),[VALUE])

 

I didn't use an external table to calculate the variable for the same day, but it seems working.

I have now 2 problems: first of all, the value for prior year is correct for each row, but the total it's not working:

 

DateCurrent Year valuePrior Year value
03/06/2020 00:0020.899,4121.205,38
04/06/2020 00:0023.559,5834.898,64
05/06/2020 00:0039.596,2641.917,59
Total84.055,2541.917,59

Basically instead of a total I'me getting the value of the latest day.

The second problem is the following: if I add to the table an additional dimension, for instance "Season", the table becomes like this:

DateSeasonCurrent Year valuePrior Year value
03/06/2020 00:00 021.205,38
03/06/2020 00:00FW192.821,5821.205,38
03/06/2020 00:00ND021.205,38
03/06/2020 00:00SS2018.077,8321.205,38
04/06/2020 00:00 034.898,64
04/06/2020 00:00FW197.504,6034.898,64
04/06/2020 00:00ND034.898,64
04/06/2020 00:00SS2016.054,9934.898,64
05/06/2020 00:00 041.917,59
05/06/2020 00:00FW198.366,9241.917,59
05/06/2020 00:00ND041.917,59
05/06/2020 00:00SS2031.229,3441.917,59
Total 84.055,2541.917,59

So the basic current year value measure is correctly split by season, my "complex" one isn't at all (and of course the total is still not a total...).

Is there a way to make it work in both situations?

Thanks a lot!

Hi @Anonymous ,

 

You may change your measure [Prior Year value], and create another new measure to correct the total sum like DAX below.

 

 

Prior Year value=

VAR _MAX_SAME_DAY = MAX ('DTC Cube'[DATE_ID_SAME_DAY])

VAR __TmpTable = CALCULATETABLE('DTC Cube',ALL('DTC Cube'[DATE_ID]))

RETURN IF([Current Year value]= BLANK(), BLANK(),  SUMX(FILTER(__TmpTable, 'DTC Cube'[DATE_ID]=_MAX_SAME_DAY ),[VALUE]) )



Prior Year value_new=

var _table = SUMMARIZE('DTC Cube', 'DTC Cube'[Date_ID],"_Value", [Prior Year value] )

return
IF(HASONEVALUE('DTC Cube'[Date_ID]), [Prior Year value], SUMX(_table,[_Value]))

 

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

Anonymous
Not applicable

Thank you Amy for your suggestion, I tried to replicate it but I still have some problems.

I've create a pbix file to facilitate our communication, you can download it here:

 

https://we.tl/t-BYGGXDettS 

 

I have 2 open point:

  1. in your formula there was a "d" after HASONEVALUE function, and I don't know what it means (in my example I put the Current Year Value measure). By the way, I'm not getting the total, sure I'm missing something.
  2. As you can see in the second table, I can't make it work when I add another dimension, like Season. Is there a way to get the also the prior year value splitted by season?

My final goal is to filter by date and season and get the value for same day and prior season.

I hope I was clear and thank you again

 

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.