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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Fill in blanks to compare dimension

Hi,

 

I got a table with;

DistancefkIDSpeed
1ID1274
2ID2273
3ID1275
3ID2274
4ID2274
5ID1275
5ID2275
6ID2276
7ID1275
7ID2276

 

When comparing the distance

DistanceID1ID2Delta
1274 274
2 273-273
32752741
4 274-274
52752750
6 276-276
7275276-1

 

I'm looking for a measure that fill in the blanks based on the previous know record

DistanceID1ID2Delta
1274 274
22742731
32752741
42752741
52752750
6275276-1
7275276-1


I tried this measure without success, IF(ISBLANK([Speed]), CALCULATE(LASTNONBLANK(Table1[Speed],0), ALLEXCEPT(Table1, Table1[Distance])), [Speed])

3 REPLIES 3
Anonymous
Not applicable

Thanks @v-yueyunzh-msft , sorry but in that table there are 1000's different IDs which I could compare not only ID1 or ID2

Hi, @Anonymous 

According to your description, you have more than two IDs. And i am not sure how to compare them. But for the show all value in Matrix , you can use this method.

(1)We need to create a dimension table:

Distance = VALUES('Table'[Distance])

 

(2)Then we create a measure:

 

Measure = var _SPEED = CALCULATE( SUM('Table'[Speed]) , 'Table'[Distance] = MAX('Distance'[Distance]))

var _t = FILTER('Table' , 'Table'[Distance] <= MAX('Distance'[Distance]))

var _max_dis =MAXX(_t,[Distance])

var _pre_speeed=sumx( FILTER(_t,[Distance]=_max_dis) , [Speed])

RETURN

IF(_SPEED=BLANK(),_pre_speeed,_SPEED)

 

Then we can meet your need:

vyueyunzhmsft_0-1676423931029.png

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

v-yueyunzh-msft
Community Support
Community Support

Hi , @Anonymous 

According to your description, you want to Fill in blanks to compare dimension.

Here are the steps you can refer to :
(1)Due to the raw data is not the whole data, we need to click "New table" to cretae two dimension tables:

Table 2 = VALUES('Table'[Distance])
Table 3 = ADDCOLUMNS( UNION( VALUES('Table'[fkID]) , {"Delta"}) , "sort" , IF([fkID]="ID1",1,IF([fkID]="ID2",2,3)))

(2)Then we can click "New measure" to create a measure:

Measure2 = var _cur_dis = MAX('Table 2'[Distance])
var _cur_id = MAX('Table 3'[fkID])
var _t = FILTER('Table','Table'[Distance]<=_cur_dis && 'Table'[fkID]= "ID1")
var _max_dis = maxx(_t,[Distance])
var _speed =MAXX( FILTER(_t,[Distance]=_max_dis) , [Speed])
var _t2 = FILTER('Table','Table'[Distance]<=_cur_dis && 'Table'[fkID]= "ID2")
var _max_dis2 = maxx(_t2,[Distance])
var _speed2 =MAXX( FILTER(_t2,[Distance]=_max_dis2) , [Speed])
return
IF(_cur_id="Delta",_speed-_speed2,IF(_cur_id="ID1",_speed,_speed2))

 

(3)Then we can meet your need , the result is as follows:

vyueyunzhmsft_0-1676340961256.png

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.