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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply

Sum or count a column if order rank 1 and order rank 2 has the same pickup date

I have my order table where I ranked all orders according to the pickup date. 
I need to sum the total mobile and laptop contribution if the rank 1 order-id and rank 2 order-id have the same pickup date. 

Screenshot 2023-01-17 231041.png
I am creating a calculated column in my customer table. My customer table and orders table have one to many relationship via the customer id. 

please help! URGENT

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Andrew_na_lang ,

Create a column.

Column = 
VAR _min_date = CALCULATE(MIN('Table use'[PICKUP DATE]),RELATEDTABLE('Table use'))
VAR _total = CALCULATE(SUM('Table use'[LAP CONTRIBUTION]),'Table use'[PICKUP DATE]=_min_date)
RETURN
_total

vpollymsft_0-1674091738858.png

If it still does not help,Please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

12 REPLIES 12
Anonymous
Not applicable

Hi @Andrew_na_lang ,

Please refer to my pbix file to see if it helps you.

Create a measure.

Measure = VAR _1=CALCULATE(SUM('Table (2)'[LAP CONTRIBUTION]),FILTER(ALL('Table (2)'),'Table (2)'[CUSTOMER ID]=SELECTEDVALUE('Table'[customer id])&&'Table (2)'[PICKUP DATE]=SELECTEDVALUE('Table (2)'[PICKUP DATE])))
VAR _2=COUNTAX(FILTER(ALL('Table (2)'),'Table (2)'[CUSTOMER ID]=SELECTEDVALUE('Table (2)'[CUSTOMER ID])&&'Table (2)'[PICKUP DATE]=SELECTEDVALUE('Table (2)'[PICKUP DATE])),'Table (2)'[PICKUP DATE])
VAR _2A=CALCULATE(MIN('Table (2)'[PICKUP DATE]),FILTER(ALL('Table (2)'),'Table (2)'[CUSTOMER ID]=SELECTEDVALUE('Table (2)'[CUSTOMER ID])))
VAR _3=CALCULATE(MAX('Table (2)'[LAP CONTRIBUTION]),FILTER(ALL('Table (2)'),'Table (2)'[CUSTOMER ID]=SELECTEDVALUE('Table (2)'[CUSTOMER ID])&&'Table (2)'[PICKUP DATE]=_2A))
RETURN 
IF(_2=2,_1,_3)

vpollymsft_0-1674021639085.pngvpollymsft_1-1674021654073.png

If it still does not help,Please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

@Anonymous  I need a calculated column actually.

Anonymous
Not applicable

Hi @Andrew_na_lang ,

Please refer to my pbix file to see if it helps you.

vpollymsft_0-1674028558265.png

 

If it still does not help,Please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

@Anonymous  Can't I create a calculated column in the customer table instead?

Anonymous
Not applicable

Hi @Andrew_na_lang ,

Create a column.

Column = 
VAR _min_date = CALCULATE(MIN('Table use'[PICKUP DATE]),RELATEDTABLE('Table use'))
VAR _total = CALCULATE(SUM('Table use'[LAP CONTRIBUTION]),'Table use'[PICKUP DATE]=_min_date)
RETURN
_total

vpollymsft_0-1674091738858.png

If it still does not help,Please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

Thank you! It worked.

Ashish_Mathur
Super User
Super User

Hi,

Share data in a format that can be pasted in an MS Excel file.  Also, show the expected result very clearly.  Why are you writing a calculated column formula in the Customer Table.  You should be using a measure in the visual instead.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur 

@Anonymous here are the tables and desired output.

Screenshot 2023-01-18 091221.png

Screenshot 2023-01-18 091209.png

Screenshot 2023-01-18 091243.png



Desired output


Screenshot 2023-01-18 091402.png

Hi,

I can help if you need a measure and that is what i think you should opt for.  If my approach suits you, then share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur the reason why I am creating a calculated column in the customer's table is because I am working on a cohort analysis where I verify whether all customers who had laptops in their first order are still ordering. 

Sharing a pbix file

Anonymous
Not applicable

Hi @Andrew_na_lang ,

Please have a try.

Create a measure.

measure =
VAR _1 =
    CALCULATE (
        SUM ( tabel[MOBILE COMTRIBUTION] ),
        FILTER (
            ALL ( table ),
            table[PICKUPDATE] = SELECTEDVALUE ( table[PICKUPDATE] )
                && table[Orderranking] = SELECTEDVALUE ( table[Orderranking] )
        )
    )
VAR _2 =
    CALCULATE (
        SUM ( tabel[LAPTOP COMTRIBUTION] ),
        FILTER (
            ALL ( table ),
            table[PICKUPDATE] = SELECTEDVALUE ( table[PICKUPDATE] )
                && table[Order ranking] = SELECTEDVALUE ( table[Order ranking] )
        )
    )
RETURN
    _1 + _2

 

How to Get Your Question Answered Quickly 

 

If it still does not help,Please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

 

@Anonymous here are the tables and desired output.

Screenshot 2023-01-18 091221.png

Screenshot 2023-01-18 091209.png

Screenshot 2023-01-18 091243.png



Desired output


Screenshot 2023-01-18 091402.png

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors