cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Microsoft
Microsoft

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
Microsoft
Microsoft

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
Microsoft
Microsoft

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

Thank you

 

It simply works!! 

Super User IV
Super User IV

@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!

Proud to be a Super User!




Super User III
Super User III

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])

 


______________


Check out my Data Stories Gallery Christmas Report: Are you on Santa's Naughty or Nice List?

______________


Has this post solved your problem? Please mark it as a 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.


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


www.excelwithallison.com

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors