Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi folks, I'm working on report that includes showing costs by week up to the current date. We want to have a data table that displays the cost in the most recent complete week for a given category. If that category had no costs in the current week, it should show as blank. Since PBI doesn't have "week" included in the date heirarchy, I have a column that labels each week.
Step one is I have a measure to identify the most recent complete week (all 7 days worth of data):
Solved! Go to Solution.
I wound up changing the "ALLEXCEPT" statement to "ALL" and removed the exception for Service Date filtering and that did the trick. Unfortunate because I would prefer to keep that filter exception but I can live without it.
I wound up changing the "ALLEXCEPT" statement to "ALL" and removed the exception for Service Date filtering and that did the trick. Unfortunate because I would prefer to keep that filter exception but I can live without it.
@harrame , if you can use week and date table , then with the help of week rank you can get a This week and last week
If you need the current week you can use a week of today or use the slicer
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
This Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
Last year Week= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -52)))
Refer : https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
@harrame Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
Here's a mock table that I drew up:
Category | SERVICE_WEEK | SERVICE_DATE | COST |
LABOR | Sep 07 - Sep 13, 2020 | 9/8/2020 | $ 5,000.00 |
MAINTENANCE | Sep 07 - Sep 13, 2020 | 9/8/2020 | $ 28,934.00 |
LABOR | Sep 07 - Sep 13, 2020 | 9/7/2020 | $ 23,483.00 |
MAINTENANCE | Sep 07 - Sep 13, 2020 | 9/7/2020 | $ 216.00 |
LABOR | Aug 31 - Sep 06, 2020 | 9/6/2020 | $ 968,468.00 |
MAINTENANCE | Aug 31 - Sep 06, 2020 | 9/6/2020 | $ 6,546.00 |
LABOR | Aug 31 - Sep 06, 2020 | 9/5/2020 | $ 9,646.00 |
MAINTENANCE | Aug 31 - Sep 06, 2020 | 9/5/2020 | $ 648.00 |
LABOR | Aug 31 - Sep 06, 2020 | 9/4/2020 | $ 64,684.00 |
MAINTENANCE | Aug 31 - Sep 06, 2020 | 9/4/2020 | $ 684,684.00 |
LABOR | Aug 31 - Sep 06, 2020 | 9/3/2020 | $ 6,843.00 |
MAINTENANCE | Aug 31 - Sep 06, 2020 | 9/3/2020 | $ 6,877.00 |
LABOR | Aug 31 - Sep 06, 2020 | 9/2/2020 | $ 7,898.00 |
MAINTENANCE | Aug 31 - Sep 06, 2020 | 9/2/2020 | $ 879,615.00 |
LABOR | Aug 31 - Sep 06, 2020 | 9/1/2020 | $ 854,968.00 |
MAINTENANCE | Aug 31 - Sep 06, 2020 | 9/1/2020 | $ 8,487.00 |
LABOR | Aug 31 - Sep 06, 2020 | 8/31/2020 | $ 849,681.00 |
MAINTENANCE | Aug 31 - Sep 06, 2020 | 8/31/2020 | $ 6,863.00 |
LABOR | Aug 24 - Aug 30, 2020 | 8/30/2020 | $ 4,654.00 |
MAINTENANCE | Aug 24 - Aug 30, 2020 | 8/30/2020 | $ 54,964.00 |
LABOR | Aug 24 - Aug 30, 2020 | 8/29/2020 | $ 4,684.00 |
MAINTENANCE | Aug 24 - Aug 30, 2020 | 8/29/2020 | $ 484.00 |
LABOR | Aug 24 - Aug 30, 2020 | 8/28/2020 | $ 84,687.00 |
MAINTENANCE | Aug 24 - Aug 30, 2020 | 8/28/2020 | $ 846,998.00 |
LABOR | Aug 24 - Aug 30, 2020 | 8/27/2020 | $ 486.00 |
MAINTENANCE | Aug 24 - Aug 30, 2020 | 8/27/2020 | $ 8,468.00 |
LABOR | Aug 24 - Aug 30, 2020 | 8/26/2020 | $ 8,468.00 |
MAINTENANCE | Aug 24 - Aug 30, 2020 | 8/26/2020 | $ 848.00 |
LABOR | Aug 24 - Aug 30, 2020 | 8/25/2020 | $ 48,748.00 |
MAINTENANCE | Aug 24 - Aug 30, 2020 | 8/25/2020 | $ 6,388.00 |
LABOR | Aug 24 - Aug 30, 2020 | 8/24/2020 | $ 846.00 |
MAINTENANCE | Aug 24 - Aug 30, 2020 | 8/24/2020 | $ 877.00 |
As you can see here, the most recent complete week would be Aug 31 - Sep 06, 2020. The goal is the following:
Category | Current Week | Current Week Cost |
LABOR | Aug 31 - Sep 06, 2020 | $ 2,762,188.00 |
MAINTENANCE | Aug 31 - Sep 06, 2020 | $ 1,593,720.00 |
TOTAL | Aug 31 - Sep 06, 2020 | $ 4,355,908.00 |
@harrame It's a bit hard to troubleshoot with a fairly complex measure; I'd calculate it in a simpler way like this,
Lates Week Cost =
VAR __max_date = MAXX ( ALL ( 'Data Table'[SERVICE_DATE] ), 'Data Table'[SERVICE_DATE] )
VAR __offset = MOD ( WEEKDAY ( __max_date, 2 ), 7 )
//if max_date is Sunday, no offset is needed; or the week starts from last Sunday
VAR __latest_week =
DATESINPERIOD ( 'Data Table'[SERVICE_DATE], __max_date - __offset, -7, DAY )
RETURN
CALCULATE( SUM( 'Data Table'[ COST ] ), __latest_week )
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |