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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ahmedaldafaae
Employee
Employee

Find the first non blank value and repeat it for the same ID

Please help in wrting a dax measure . TPID has multiple managers (MWA) and I need to repeat the first manager for the same tpid. as shown below 

 TPID       MWA              Desired Values

1JameJame
1BillyJame
1CamyJame
1BillyJame
2 Billy
2BillyBilly
2CamyBilly
2 Billy
3AmmarAmmar
3AmmarAmmar
3 Ammar
3CamyAmmar
   
1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hello @ahmedaldafaae ,

According to my understanding, you want to use the first non-blank value in each id group as the value of the same group, right?

You can use the following formula after adding an index column:

Measure =
VAR _firstnoblank =
    CALCULATE (
        MIN ( 'Table'[Index] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[TPID] = MAX ( 'Table'[TPID] )
                && 'Table'[MWA] <> BLANK ()
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[MWA] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = _firstnoblank )
    )

My visualization looks like this:
11.3.3.1.PNG

Here's the pbix file.

Have I answered your question? Please mark my answer as a solution. Thanks a lot.
If not, load some samples of insensitive data and expected output.

Best regards
Eyelyn Qin

View solution in original post

4 REPLIES 4
v-eqin-msft
Community Support
Community Support

Hello @ahmedaldafaae ,

According to my understanding, you want to use the first non-blank value in each id group as the value of the same group, right?

You can use the following formula after adding an index column:

Measure =
VAR _firstnoblank =
    CALCULATE (
        MIN ( 'Table'[Index] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[TPID] = MAX ( 'Table'[TPID] )
                && 'Table'[MWA] <> BLANK ()
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[MWA] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = _firstnoblank )
    )

My visualization looks like this:
11.3.3.1.PNG

Here's the pbix file.

Have I answered your question? Please mark my answer as a solution. Thanks a lot.
If not, load some samples of insensitive data and expected output.

Best regards
Eyelyn Qin

Thank you

 

It simply works!! 

Fowmy
Super User
Super User

@ahmedaldafaae 

I tried a Power Query solution adding just one custom column:

Fowmy_0-1604217490883.png


Paste the below code in a blank Query in the Advanced Editor and check the step added.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJKzE1VitWBcJwyc3Iq4TznxNxKLFJGQJ4CnIUqDteCUGQMZDnm5iYW4eAhVEE0xwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TPID = _t, MWA = _t]),
    #"Added Custom" = Table.AddColumn(Source, "New MWA", (r)=>  List.First(Table.SelectRows(Source, each [TPID]  = r[TPID] and [MWA] <> " ")[MWA]))
in
    #"Added Custom"

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

AllisonKennedy
Super User
Super User

Is there another column that determines the order - we need a way to tell Power BI which value is 'first'. If you don't have a column for this, use Power Query Editor to add an Index column.

Then you can use something similar to this as a calculated column:

MWA Desired =
VAR _ThisTPID = 'Table'[TPID]
VAR _tblTPIDvalues = FILTER(ALL('Table'), 'Table'[TPID] = _ThisTPID && NOT(ISBLANK('Table'[MWA])))
VAR _Index = MINX(_tblTPIDvalues, 'Table'[Index])
RETURN
MINX(FILTER(_tblTPIDvalues, _Index = 'Table'[Index]), 'Table'[MWA])

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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