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
iamprajot
Responsive Resident
Responsive Resident

Sum of first Order ID / last Order ID / unique Order ID

Hi, I need the SUM of the Sales but for below conditions:-

 

1, Sum of Sales based on First Order ID - means sum only the Sales amount for the first occurence of the Order ID

2, Sum of Sales based on Last Order ID - means sum only the Sales amount for the last occurence of the Order ID

3, Sum of Sales based on Distinct Order ID - means average of the single Order ID and then the Sum

 

Below is the Sample Table for Office Supplies.

 

Order IDSales
8852213.01
901936362.85
90192211.15
868381164.45
8683822.23
8683813.99
8683814.26
8683733.47
86839379.53
8683618.8
86836945.99
90031455.77
90032231.79
417931876.69
42949293.06
42949914.29
8765167.49
876512.25
8765254.78
89199424.68
8920040.17
89202783.55
892033838.14
8920158.68
8920153.1
91454647.07
88426627.04
884253267.55
88426110.19
8807573.55
8807529.57
8740722.85
87408506.39
874064
87406589.8
879461225.6
375371239.06
375374083.19
375374902.38
557135718.85
879471400.53
873651821.89
8736490.98
8736610728
905963127.69
9059741.82
905972875.72
87175170.8
1 ACCEPTED SOLUTION
v-danhe-msft
Employee
Employee

Hi @iamprajot,

Based on my test, you can refer to below steps:

1.Create an Index column like the picture below:

1.PNG

2.Create two measures to calculate the First/Last sum value.

First sum value = var t=SUMMARIZE('Table1','Table1'[Order ID],"salenew",LOOKUPVALUE('Table1'[Sales],'Table1'[Order ID],'Table1'[Order ID],'Table1'[Index],CALCULATE(MIN('Table1'[Index]),ALLEXCEPT(Table1,'Table1'[Order ID]))))

return

SUMX(t,[salenew])

Last sum value = var t=SUMMARIZE('Table1','Table1'[Order ID],"salenew",LOOKUPVALUE('Table1'[Sales],'Table1'[Order ID],'Table1'[Order ID],'Table1'[Index],CALCULATE(MAX('Table1'[Index]),ALLEXCEPT(Table1,'Table1'[Order ID]))))

return

SUMX(t,[salenew])

3.Create a new table and a new measure to calculate the average sum value.

New Table = GROUPBY (

        Table1,

        Table1[Order ID],

        "Group by ID", AVERAGEX(  CURRENTGROUP (), Table1[Sales])

)

Average sum value = SUM('New Table'[Group by ID])

3.PNG

4.Create three Card visual and add the related fields and you can see the result.

2.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/3acx04jiiyahlrx/Sum%20of%20first%20Order%20ID%20last%20Order%20ID%20unique...

 

Regards,

Daniel He

Community Support Team _ Daniel He
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

1 REPLY 1
v-danhe-msft
Employee
Employee

Hi @iamprajot,

Based on my test, you can refer to below steps:

1.Create an Index column like the picture below:

1.PNG

2.Create two measures to calculate the First/Last sum value.

First sum value = var t=SUMMARIZE('Table1','Table1'[Order ID],"salenew",LOOKUPVALUE('Table1'[Sales],'Table1'[Order ID],'Table1'[Order ID],'Table1'[Index],CALCULATE(MIN('Table1'[Index]),ALLEXCEPT(Table1,'Table1'[Order ID]))))

return

SUMX(t,[salenew])

Last sum value = var t=SUMMARIZE('Table1','Table1'[Order ID],"salenew",LOOKUPVALUE('Table1'[Sales],'Table1'[Order ID],'Table1'[Order ID],'Table1'[Index],CALCULATE(MAX('Table1'[Index]),ALLEXCEPT(Table1,'Table1'[Order ID]))))

return

SUMX(t,[salenew])

3.Create a new table and a new measure to calculate the average sum value.

New Table = GROUPBY (

        Table1,

        Table1[Order ID],

        "Group by ID", AVERAGEX(  CURRENTGROUP (), Table1[Sales])

)

Average sum value = SUM('New Table'[Group by ID])

3.PNG

4.Create three Card visual and add the related fields and you can see the result.

2.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/3acx04jiiyahlrx/Sum%20of%20first%20Order%20ID%20last%20Order%20ID%20unique...

 

Regards,

Daniel He

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

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.