Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
doamss
New Member

Measure wont aggregate then taking fallback values

Hi, I have made a measure, which would not aggregate correctly and can't figure out how to solve it.

Shortly, there are three tables: Reisai [Columns: Reisas (ID of a trip)], Reisai_detaliai [Details of each trip; Columns: Reisas (ID), Pradzia (start of trip), Vilkikas (truck ID)], Kuras [Fuel used, Columns: Reisas (ID), Kiekis (amount used)]. Fuel table does not have unique values and some trips does not have fuel. I want to create a measure, which would take fuel for each trip, and if there are no fuel, take from the last trip with fuel the amount (regardless of filters). Here's what I came up with:

Kiekis with Fallback =
VAR CurrentReisas = SELECTEDVALUE(Reisai[Reisas])
VAR CurrentPradzia = SELECTEDVALUE(Reisai_detaliai[Pradzia])
VAR CurrentVilkikas = SELECTEDVALUE(Reisai_detaliai[Vilkikas])
VAR LastValidPradzia = MAXX(
FILTER(
ALL(Reisai_detaliai),
Reisai_detaliai[Pradzia] < CurrentPradzia && Reisai_detaliai[Vilkikas] = CurrentVilkikas &&
NOT(ISBLANK(CALCULATE(SUM(Kuras[Kiekis]))))
),
Reisai_detaliai[Pradzia]
)
VAR LastKiekis = CALCULATE(SUM(
Kuras[Kiekis])
,filter(ALL(Reisai_detaliai), Reisai_detaliai[Vilkikas]=CurrentVilkikas  && Reisai_detaliai[Pradzia] = LastValidPradzia)
 )
VAR Kiekis = CALCULATE(SUM(Kuras[Kiekis]))
RETURN
IF(      ISBLANK(Kiekis),      LastKiekis,      Kiekis )

Unfortunately, it would aggregate ONLY values that has Kiekis for specific trip, but not for LastKiekis. How do I fix it, so that the aggregate would take AVERAGE of ALL values that are either directly related or taken from last trip?

 
doamss_1-1710661015366.png

 

Thank you so much!

Note: there are filtered out values, the table is huge, and i want to take it into account.

3 REPLIES 3
doamss
New Member

Yes, how can it help? Is it just to replace ISBLANK?

yes, it is a convenience function to probe for Blank and replace with a different value if needed.

lbendlin
Super User
Super User

Are you familiar with COALESCE()  ?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors