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.
Hi,
I have a table that captures registrations for events and this table has 2 date fields - RegistrationDate and EventStartDate.
I need to calculate the cumulative No. of registrations for each event from the previous 52 weeks until the event starts (illustrated below).
ESD = Event Start Date
EventName | ESD-52week | ESD-51week | ESD-50week | ... | ESD-2week | ESD-1week | ESD-0week | |
Event1 | 0 | 4 | 7 | ... | 15 | 20 | 44 | |
Event2 | 7 | 7 | 27 | ... | 35 | 42 | 54 | |
Event3 | 15 | 21 | 33 | ... | 35 | 47 | 66 |
The last numbers (44, 54, 66) are the total registrations for the respective events.
Calculation on the registrations need to be on RegistrationDate and reaches its max at EventStartDate.
A tabular representation would work fine for me.
Any ideas on how this can be achieved, please?
Thanks in advance!
Solved! Go to Solution.
The simplest way to do this would be just add a calculated column to your table with this formula
RegistrationWeek = DATEDIFF(Table[EventStartDate], Table[RegistrationDate], WEEK)
That will give you # of weeks before the event (-1,-42, etc.). You can then make a matrix with Event on the rows and the new column on the Columns, and use a running total measure like this
Cumulative Registrations =
VAR __thisweek =
SELECTEDVALUE ( Table[RegistrationWeek] )
RETURN
CALCULATE (
COUNTROWS ( Table ),
ALL ( Table[RegistrationWeek] ),
Table[RegistrationWeek] <= __thisweek
)
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
The simplest way to do this would be just add a calculated column to your table with this formula
RegistrationWeek = DATEDIFF(Table[EventStartDate], Table[RegistrationDate], WEEK)
That will give you # of weeks before the event (-1,-42, etc.). You can then make a matrix with Event on the rows and the new column on the Columns, and use a running total measure like this
Cumulative Registrations =
VAR __thisweek =
SELECTEDVALUE ( Table[RegistrationWeek] )
RETURN
CALCULATE (
COUNTROWS ( Table ),
ALL ( Table[RegistrationWeek] ),
Table[RegistrationWeek] <= __thisweek
)
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hi @mahoneypat ,
As per your suggestion, this is what I could achieve.
There are a couple more things that I would like to know :
Question 1 - How can I populate the empty cells with the same previous value? (For eg - the highlighted part should contain 150 for -3, -2, -1 and 0 weeks)
Question 2 - If I select only events that has gaps, even the header (RegistrationWeek) skips the columns that has no data. How can I keep this static to always show 0 to -52 even if there is no data? (this is related to Question 1 as there is no data to show in that column)
The reason you are seeing blanks is that there are no rows for that week, so there is not a RegistrationWeek value to go in the first part with SELECTEDVALUE(). To get around that there are two approaches that could work. I recommend the second one:
1. Add blank rows in the query editor to fill in the missing dates/weeks (e.g., make a full list of dates/weeks, convert to table, and then merge your data into it for each customer)
2. Make a disconnected table of regisration week numbers (e.g., with GENERATESERIES(-42,1,1) or something like that and use that in your columns. Then modify the measure expression to get the SELECTEDVALUE() of that column.
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Went by the second approach and that helped... Thank you! 😊
This is excellent Pat... Thanks a ton.
Your solution is just about right. I can modify the rest as per the requirement.
So looking back 52 weeks but not before the registration date, or will there not be any registratios anyway before the registration date?
Proud to be a Super User!
Awesome Keyboard Shortcusts in Power BI, thumbs up if you like the article
My Community Blog Articles (check them out!)
My Blog - Power M code to automatically detect column types -
How to create test data using DAX!
Hi @harshnathani ,
The criticality of my requirement is that we have 2 separate date fields and the calculation is based on both.
No. of registrations are being calculated on the RegistrationDate, whereas the offset needs to be calculated on the EventStartDate.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
49 | |
26 | |
20 | |
15 | |
12 |
User | Count |
---|---|
57 | |
49 | |
43 | |
19 | |
18 |