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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
adelmonte
Resolver I
Resolver I

Table with most recent update of quantity per depo

Hello Everyone,

I have a table with Orders, Products, Delivery Date, Email update date, Email update time, Depo1, Depo2
I receive up to 4 updates of initial order per day for one OrderID, and Delivery Date where quantity can change.
I would need a columns with the latest updated quantity, one column with old quantity per Depo1 and Depo2 the same.

 

Thanks in advance for your help!

 

RAW Table

Table 1.png

Desired outcome

Wished Results.png

 

Google Spreadsheet:
https://bit.ly/3m9PdVa

 

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

Hi @adelmonte ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Add a custom column for email time with date and time in Power Query Editor

yingyinr_0-1635320683925.png

2. Select all Depo_xx columns and unpivot all of these selected columns

= Table.Unpivot(#"Changed Type1", {"Depo_01", "Depo_02", "Depo_03", "Depo_04", "Depo_05", "Depo_06", "Depo_07", "Depo_08", "Depo_09", "Depo_10"}, "Depos", "Value")

yingyinr_1-1635320763584.png

3. Create the measures as below to get the value of Depo and UPD_Depo

> Get the value of Depo

Temp_Depo = 
VAR _selordid =
    SELECTEDVALUE ( 'Table'[Order ID] )
VAR _seldepo =
    SELECTEDVALUE ( 'Table'[Depos] )
VAR _maxemailtime =
    CALCULATE (
        MAX ( 'Table'[Email Datetime] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Order ID] = _selordid )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[Order ID] = _selordid
                && 'Table'[Depos] = _seldepo
                && 'Table'[Email Datetime] = _maxemailtime
        )
    )
nDepo = SUMX(GROUPBY('Table','Table'[Order ID],'Table'[Depos]),[Temp_Depo])

>Get the value of UPD_Depo

Temp_UPD_Depo = 
VAR _selordid =
    SELECTEDVALUE ( 'Table'[Order ID] )
VAR _seldepo =
    SELECTEDVALUE ( 'Table'[Depos] )
VAR _minemailtime =
    CALCULATE (
        MIN ( 'Table'[Email Datetime] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Order ID] = _selordid )
    )
VAR _mindepo =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Order ID] = _selordid
                && 'Table'[Depos] = _seldepo
                && 'Table'[Email Datetime] = _minemailtime
        )
    )
RETURN
    IF ( ISBLANK ( [Temp_Depo] ), BLANK (), [Temp_Depo] - _mindepo )
UPD_Depo = SUMX(GROUPBY('Table','Table'[Order ID],'Table'[Depos]),[Temp_UPD_Depo])

yingyinr_2-1635322015860.png

But the UPD_Depo value I get is not the same as yours... Is UPD_Depo the value of the latest mail date - the value of the oldest mail date? For example, if the order id is ID210081409, the latest value of Depo_1 is 672, and the value of the oldest mail date and time is 560, the final result should be 672-560=112, but why your value is 0? If my understanding is wrong, please help me to correct and provide more explanation on the logic of UPD_Depo calculation. Thank you.

yingyinr_3-1635322238403.png

Your desired outputYour desired output

My gotten valueMy gotten value

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @adelmonte ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Add a custom column for email time with date and time in Power Query Editor

yingyinr_0-1635320683925.png

2. Select all Depo_xx columns and unpivot all of these selected columns

= Table.Unpivot(#"Changed Type1", {"Depo_01", "Depo_02", "Depo_03", "Depo_04", "Depo_05", "Depo_06", "Depo_07", "Depo_08", "Depo_09", "Depo_10"}, "Depos", "Value")

yingyinr_1-1635320763584.png

3. Create the measures as below to get the value of Depo and UPD_Depo

> Get the value of Depo

Temp_Depo = 
VAR _selordid =
    SELECTEDVALUE ( 'Table'[Order ID] )
VAR _seldepo =
    SELECTEDVALUE ( 'Table'[Depos] )
VAR _maxemailtime =
    CALCULATE (
        MAX ( 'Table'[Email Datetime] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Order ID] = _selordid )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[Order ID] = _selordid
                && 'Table'[Depos] = _seldepo
                && 'Table'[Email Datetime] = _maxemailtime
        )
    )
nDepo = SUMX(GROUPBY('Table','Table'[Order ID],'Table'[Depos]),[Temp_Depo])

>Get the value of UPD_Depo

Temp_UPD_Depo = 
VAR _selordid =
    SELECTEDVALUE ( 'Table'[Order ID] )
VAR _seldepo =
    SELECTEDVALUE ( 'Table'[Depos] )
VAR _minemailtime =
    CALCULATE (
        MIN ( 'Table'[Email Datetime] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Order ID] = _selordid )
    )
VAR _mindepo =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Order ID] = _selordid
                && 'Table'[Depos] = _seldepo
                && 'Table'[Email Datetime] = _minemailtime
        )
    )
RETURN
    IF ( ISBLANK ( [Temp_Depo] ), BLANK (), [Temp_Depo] - _mindepo )
UPD_Depo = SUMX(GROUPBY('Table','Table'[Order ID],'Table'[Depos]),[Temp_UPD_Depo])

yingyinr_2-1635322015860.png

But the UPD_Depo value I get is not the same as yours... Is UPD_Depo the value of the latest mail date - the value of the oldest mail date? For example, if the order id is ID210081409, the latest value of Depo_1 is 672, and the value of the oldest mail date and time is 560, the final result should be 672-560=112, but why your value is 0? If my understanding is wrong, please help me to correct and provide more explanation on the logic of UPD_Depo calculation. Thank you.

yingyinr_3-1635322238403.png

Your desired outputYour desired output

My gotten valueMy gotten value

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This is great!
Many many thanks for your help.
It works perfectly well the way you did it with the difference from last and first email.
I just wanted to know if I can repeat all item labels on Row Headers in Matrix Visual

Repeat all Item Labels.png
Regards,
Alex

amitchandak
Super User
Super User

@adelmonte , Create a new column as flag and use that

Create a new email date time first

 

email date time = [email date] + [email time]

 

Flag =

if( [email date time] = maxx(filter(Table, [Order Id] = earlier([Order Id]))  [email date time] ),1,0)

 

filter for 1 in visual or measure

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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