The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi everyone,
I have sales broken out into a weekly view. The sales are a calculated measure, [Demand] and the SKU, [SKU], and Week Start Date, [Week Start date], are columns.
I'm trying to write a measure that says "look at the last non-blank value and copy it foward", i.e. the end result would be the number 19 being shown on weeks 1/17/2021 and 1/24/202.
I have an if statement already working, saying "if before 12/20/2020, ignore this formula", since I only care about the blanks being filled after then.
Currently (without the if statement above) my formula is adding the measure [Demand]
This is my formula below:
=
CALCULATE([Demand],
FILTER(ALL('All Transactions'),
'All Transactions'[Week Number] = SELECTEDVALUE('All Transactions'[Week Number]) -1
&&
'All Transactions'[Year] = SELECTEDVALUE('All Transactions'[Year])
))
But when I run the measure, it does this instead:
Is there any way someone can help me out? Essentially, I'm trying to use the LASTNONBLANK() formula, but that doesn't work unless it's referencing a column
I've looked throughout the community and found these similar situations, but couldn't figure out why this isn't working. (There are no other tables, so it's not a connection issue imo)
Thank you for your time and help!
Jake
Hi @wsgjamesabl ,
Don't know how your model is setup and what is the DEMAND formula but believe you can do something similar to this.
Create a table with the week values:
WeeksDates = DISTINCT('Cost'[Date])
Now add the following measure:
TotalOrders =
VAR temp_table =
SUMMARIZE (
FILTER ( ALL ( 'Cost' ); 'Cost'[Date] < MAX ( 'WeeksDates'[Date] ) );
'Cost'[Date];
'Cost'[SKU];
'Cost'[Quantity]
)
VAR totalQuantity =
CALCULATE (
SUM ( 'Cost'[Quantity] );
TREATAS ( VALUES ( 'WeeksDates'[Date] ); 'Cost'[Date] )
)
VAR MaximumDate =
MAXX (
FILTER ( temp_table; 'Cost'[SKU] IN VALUES ( 'Cost'[SKU] ) );
'Cost'[Date]
)
VAR Demand =
SUMX (
FILTER (
temp_table;
'Cost'[SKU]
IN VALUES ( 'Cost'[SKU] )
&& 'Cost'[Date] = MaximumDate
);
Cost[Quantity]
)
RETURN
IF ( ISBLANK ( totalQuantity ); Demand; totalQuantity )
See result below:
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em Português