Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
I've been messing around with this for a few days now and can't seem to get it to work. Here's a small truncated sample set of data.
Salesperson | Week | Year | Sales $ |
Jon | 12 | 2018 | $ 500 |
Jon | 15 | 2019 | $ 100 |
Dave | 16 | 2019 | $ 150 |
Dave | 17 | 2019 | $ 125 |
Jon | 17 | 2019 | $ 125 |
Dave | 45 | 2019 | $ 100 |
Jon | 45 | 2019 | $ 150 |
Dave | 6 | 2020 | $ 175 |
Dave | 15 | 2020 | $ 150 |
Jon | 17 | 2020 | $ 100 |
I'm trying to get a matrix visual similar to this.
Current Year | Current Year | Current Year | Current Year | Prior Yr | Prior Yr | |
Salesperson | Week Sales # | Week Sales Revenue | YTD Sales # | YTD Sales Revenue | PY YTD Sales # | PY YTD Revenue |
Jon | 1 | 100 | 1 | 100 | 2 | 225 |
Dave | 0 | 0 | 2 | 325 | 2 | 275 |
My hang up is with the prior year columns. I cannot get them to work out correctly.
THe report was a 2 step slicer where you select the year and then the week. I've seen others combine the 2 into a week-year look (22-2020) but I'd like to keep it as is. I've created a seperate calendar table with no relationship to the sales table. The week slicer is using the week number from the calendar table whereas the year slicer is using the year from the sales table. I'm doing it this way because I also have a bar chart visual in the report that is displaying the sales by week for the full year.
Any help would be appreciated. Thanks!
Solved! Go to Solution.
Hi @kkassel ,
I have created these following measures to try to achieve it:
Current year week sales =
VAR _re =
COUNTROWS (
FILTER (
SUMMARIZE (
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Week] = SELECTEDVALUE ( 'Calendar'[Week] )
),
'Table'[Salesperson],
'Table'[Week],
'Table'[Year]
),
[Salesperson] = SELECTEDVALUE ( 'Table'[Salesperson] )
)
)
RETURN
IF ( ISBLANK ( _re ), 0, _re )
Current year #week sales revenue =
VAR _re =
SUMX (
FILTER (
SUMMARIZE (
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Week] = SELECTEDVALUE ( 'Calendar'[Week] )
),
'Table'[Salesperson],
'Table'[Sales $],
'Table'[Week],
'Table'[Year]
),
[Salesperson] = SELECTEDVALUE ( 'Table'[Salesperson] )
),
'Table'[Sales $]
)
RETURN
IF ( ISBLANK ( _re ), 0, _re )
Current year YTD sales = COUNTROWS('Table')
Current year #YTD sales revenue = SUM('Table'[Sales $])
Prior year YTD sales =
VAR _re =
COUNTROWS (
FILTER (
ALL ( 'Table' ),
[Salesperson] = SELECTEDVALUE ( 'Table'[Salesperson] )
&& [Year]
= SELECTEDVALUE ( 'Table'[Year] ) - 1
)
)
RETURN
IF ( ISBLANK ( _re ), 0, _re )
Prior year #YTD sales revenue =
VAR _re =
SUMX (
FILTER (
ALL ( 'Table' ),
[Salesperson] = SELECTEDVALUE ( 'Table'[Salesperson] )
&& [Year]
= SELECTEDVALUE ( 'Table'[Year] ) - 1
),
'Table'[Sales $]
)
RETURN
IF ( ISBLANK ( _re ), 0, _re )
The sample result may like is (example: 2020 week 17)
Sample file is attached that hopes to help you, please check and try it: Calculating week, ytd, and prior ytd with 2 step slicer.pbix
Best Regards,
Yingjie Li
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hi @kkassel ,
I have created these following measures to try to achieve it:
Current year week sales =
VAR _re =
COUNTROWS (
FILTER (
SUMMARIZE (
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Week] = SELECTEDVALUE ( 'Calendar'[Week] )
),
'Table'[Salesperson],
'Table'[Week],
'Table'[Year]
),
[Salesperson] = SELECTEDVALUE ( 'Table'[Salesperson] )
)
)
RETURN
IF ( ISBLANK ( _re ), 0, _re )
Current year #week sales revenue =
VAR _re =
SUMX (
FILTER (
SUMMARIZE (
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Week] = SELECTEDVALUE ( 'Calendar'[Week] )
),
'Table'[Salesperson],
'Table'[Sales $],
'Table'[Week],
'Table'[Year]
),
[Salesperson] = SELECTEDVALUE ( 'Table'[Salesperson] )
),
'Table'[Sales $]
)
RETURN
IF ( ISBLANK ( _re ), 0, _re )
Current year YTD sales = COUNTROWS('Table')
Current year #YTD sales revenue = SUM('Table'[Sales $])
Prior year YTD sales =
VAR _re =
COUNTROWS (
FILTER (
ALL ( 'Table' ),
[Salesperson] = SELECTEDVALUE ( 'Table'[Salesperson] )
&& [Year]
= SELECTEDVALUE ( 'Table'[Year] ) - 1
)
)
RETURN
IF ( ISBLANK ( _re ), 0, _re )
Prior year #YTD sales revenue =
VAR _re =
SUMX (
FILTER (
ALL ( 'Table' ),
[Salesperson] = SELECTEDVALUE ( 'Table'[Salesperson] )
&& [Year]
= SELECTEDVALUE ( 'Table'[Year] ) - 1
),
'Table'[Sales $]
)
RETURN
IF ( ISBLANK ( _re ), 0, _re )
The sample result may like is (example: 2020 week 17)
Sample file is attached that hopes to help you, please check and try it: Calculating week, ytd, and prior ytd with 2 step slicer.pbix
Best Regards,
Yingjie Li
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Thank you @v-yingjl that works but I have another question regarding the visual. When I add subtotals to total up the rows, I get 0 for current year week sales, current year #week sales revenue, prior year ytd sales, and prior year #ytd sales revenue. Why is that and how can i correct it so it totals correctly?
@kkassel , Are you using time intelligence with date calendar
example
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Refer for Week, Also check comment for last year
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...
Appreciate your Kudos.
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
65 |
User | Count |
---|---|
135 | |
116 | |
101 | |
71 | |
61 |