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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
VazhaPBI
Frequent Visitor

HELP - Calculated Column Sales Between Dates For Each Row

Hello World,

 

Need help to calculate Sales Amount between Start Date and End Date, for each agreementID independently, Table A and Table B are Related with clientID, when i try to calculate column it sums amount only on 1st client ID, I need amount for each row independently even if there are same client ID's. 

 

Untitled.png

 

 

1 ACCEPTED SOLUTION

Hi, @VazhaPBI 

 

Try this function. There is no relationship between the two tables.

Sales Amount = 
CALCULATE (
    SUM ( 'Table B'[Sales Amount] ),
    FILTER (
        'Table B',
        [Date] >= EARLIER ( 'Table A'[Start Date] )
            && [Date] <= EARLIER ( 'Table A'[End Date] )
            &&[ClientID]=EARLIER('Table A'[ClientID])
    )
)

 

Best Regards,

Community Support Team _Charlotte

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

7 REPLIES 7
v-zhangti
Community Support
Community Support

Hi, @VazhaPBI 

 

You can try the following methods.
Column:

Sales Amount =
CALCULATE (
    SUM ( 'Table B'[Sales Amount] ),
    FILTER (
        'Table B',
        [Date] >= EARLIER ( 'Table A'[Start Date] )
            && [Date] <= EARLIER ( 'Table A'[End Date] )
    )
)

vzhangti_0-1669772716025.png

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

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

Thank You, for reply but I still have same problem, uploading some more  screenshots. i cant understand what im doing wrong.

 

Model.pngSales Table.pngresult.png

Hi, @VazhaPBI 

 

Note that no relationship is required between the two calculated tables.

vzhangti_0-1669864622645.png

 

Best Regards,

Community Support Team _Charlotte

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

 

But how expression understands without relationship, which client ID to sum up, if I have several other client iD,s in data, if not relationship than i have to use CLientID = CLientID and I still get same result. I just need it to make sum for every row independently, but what it does is just sum on one row with earlier start date.

Hi, @VazhaPBI 

 

Try this function. There is no relationship between the two tables.

Sales Amount = 
CALCULATE (
    SUM ( 'Table B'[Sales Amount] ),
    FILTER (
        'Table B',
        [Date] >= EARLIER ( 'Table A'[Start Date] )
            && [Date] <= EARLIER ( 'Table A'[End Date] )
            &&[ClientID]=EARLIER('Table A'[ClientID])
    )
)

 

Best Regards,

Community Support Team _Charlotte

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

tamerj1
Super User
Super User

Hi @VazhaPBI 

Please try

Sales Amount =
SUMX (
FILTER (
RELATEDTABLE ( TableB ),
TableB[Date] >= TableA[Start Date]
&& TableB[Date] <= TableA[End Date]
),
TableB[Sales Amount]
)

Thank you tamerj1 but i still have same problem, cant figure out why 😞 I uploaded more screenshots in reply above, both solutions posted give me same result. Sales Amount for only one row not both rows.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors