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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
munnaz
Frequent Visitor

Latest values from table

Hi All, New here and to powerBi and this seems to more difficult that first imagined. 

 

I have some inspection and replacement tables that i would like to return the latest relavent data to.

INSPECTION TABLE     
InspectionIDASSETIDCOMPONENTIDMeasurementDateOccuredComments
1A1294501/01/2020 
2A12951001/01/2020 
3A1294555/02/2020 
4A12951055/02/2020 
5A1294606/03/2020NEEDS REPLACE
6A12951106/03/2020 
7A1555506/03/2020NEW
8A1555518/04/2020GOOD
9A12951118/04/2020 
10B166158/04/2020 
11B166169/05/2020 
12B16611111/06/2020replace next
13B1841112/06/2020 
14C5108/04/2020All ok
15C5108/05/2020 
16C51111/06/2020 
17C6228/04/2020 
18C6228/05/2020All good
19C62211/06/2020 

 

 

COMPONENTID  
ASSET IDCOMPONENTIDINSTALLED DATEName
A12941/01/2020Impeller
A12951/01/2020Nozzle
A15556/03/2020Impeller
B16618/04/2020Impeller
B184112/06/2020Impeller
C58/04/2020Seal
C68/04/2020Seal

 

Where the component table has a 1 to many relationship to the inspection table.

I would like to find the latest measurements, latest dates installed and last comments.

My expected results are as follows:

Last installed 
ASSET IDNameDate
AImpeller6/03/2020
ANozzle1/01/2020
BImpeller12/06/2020
CSeal8/04/2020
CNozzle8/04/2020

 

 

Last Comment  
ASSET IDnameDateComment
AImpeller8/04/2020GOOD
ANozzle  
BImpeller12/06/2020REPLACED ON DAY
CSeal8/04/2020All ok
CNozzle8/05/2020

All good

 

 

Last measurementMeasurementDateOccured
AImpeller518/04/2020
ANozzle1118/04/2020
BImpeller112/06/2020
CSeal1111/06/2020
CNozzle2211/06/2020

 

Any help is really appreciated!

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @munnaz ,

According to my understand , you want to display the lastest installed date ,the lastest but not blank comment and the latest measurement, right?

You could use the following formula after doing "Merge" .  Here is the pbix file.

1.The latest installed

LastInstalled =
CALCULATE (
    MAX ( 'COMPONENTID'[INSTALLED DATE] ),
    ALLEXCEPT ( COMPONENTID, COMPONENTID[ASSET ID] )
)

2.The latest comment

lastComment =
VAR hasBlank =
    IF ( MAX ( 'Merge1'[Comments] ) = BLANK (), 0, 1 )
VAR sumBlank =
    SUMX (
        FILTER (
            ALL ( 'Merge1' ),
            [ASSETID] = MAX ( 'Merge1'[ASSETID] )
                && [Name] = MAX ( 'Merge1'[Name] )
        ),
        hasBlank
    )
VAR _lastComment =
    MAXX (
        FILTER (
            ALL ( Merge1 ),
            [ASSETID] = SELECTEDVALUE ( Merge1[ASSETID] )
                && [Name] = SELECTEDVALUE ( Merge1[Name] )
                && NOT ( ISBLANK ( Merge1[Comments] ) )
                && [DateOccured]
                    = CALCULATE (
                        MAX ( Merge1[DateOccured] ),
                        FILTER (
                            ALL ( 'Merge1' ),
                            [ASSETID] = SELECTEDVALUE ( Merge1[ASSETID] )
                                && [Name] = SELECTEDVALUE ( Merge1[Name] )
                                && [Comments] <> ""
                        )
                    )
        ),
        [Comments]
    )
RETURN
    IF ( sumBlank = 0, BLANK (), _lastComment )

 

3.Apply this measure to filter (set as "1") for last measurement.

rank =
RANKX (
    FILTER (
        ALL ( Merge1 ),
        'Merge1'[ASSETID] = MAX ( 'Merge1'[ASSETID] )
            && 'Merge1'[Name] = MAX ( 'Merge1'[Name] )
    ),
    CALCULATE ( MAX ( ( 'Merge1'[DateOccured] ) ) ),
    ,
    DESC
)

My visualization looks like this:

9.24.6.1.PNG

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

Best Regards,
Eyelyn Qin

View solution in original post

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

Hi @munnaz ,

According to my understand , you want to display the lastest installed date ,the lastest but not blank comment and the latest measurement, right?

You could use the following formula after doing "Merge" .  Here is the pbix file.

1.The latest installed

LastInstalled =
CALCULATE (
    MAX ( 'COMPONENTID'[INSTALLED DATE] ),
    ALLEXCEPT ( COMPONENTID, COMPONENTID[ASSET ID] )
)

2.The latest comment

lastComment =
VAR hasBlank =
    IF ( MAX ( 'Merge1'[Comments] ) = BLANK (), 0, 1 )
VAR sumBlank =
    SUMX (
        FILTER (
            ALL ( 'Merge1' ),
            [ASSETID] = MAX ( 'Merge1'[ASSETID] )
                && [Name] = MAX ( 'Merge1'[Name] )
        ),
        hasBlank
    )
VAR _lastComment =
    MAXX (
        FILTER (
            ALL ( Merge1 ),
            [ASSETID] = SELECTEDVALUE ( Merge1[ASSETID] )
                && [Name] = SELECTEDVALUE ( Merge1[Name] )
                && NOT ( ISBLANK ( Merge1[Comments] ) )
                && [DateOccured]
                    = CALCULATE (
                        MAX ( Merge1[DateOccured] ),
                        FILTER (
                            ALL ( 'Merge1' ),
                            [ASSETID] = SELECTEDVALUE ( Merge1[ASSETID] )
                                && [Name] = SELECTEDVALUE ( Merge1[Name] )
                                && [Comments] <> ""
                        )
                    )
        ),
        [Comments]
    )
RETURN
    IF ( sumBlank = 0, BLANK (), _lastComment )

 

3.Apply this measure to filter (set as "1") for last measurement.

rank =
RANKX (
    FILTER (
        ALL ( Merge1 ),
        'Merge1'[ASSETID] = MAX ( 'Merge1'[ASSETID] )
            && 'Merge1'[Name] = MAX ( 'Merge1'[Name] )
    ),
    CALCULATE ( MAX ( ( 'Merge1'[DateOccured] ) ) ),
    ,
    DESC
)

My visualization looks like this:

9.24.6.1.PNG

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

Best Regards,
Eyelyn Qin

Amazing! You're a legend @v-eqin-msft !!! Thank you so much for this

Greg_Deckler
Super User
Super User

@munnaz See if Lookup Min/Max works for you. Basically you lookup the latest date/index/whatever and then use that to return the value you want.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434

 

@ me in replies if you still need help.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  thanks for the reply mate! But i am still unsure on how to proceed especially since i have a combination of 2 or more values to give me a result. 

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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