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
colourfullife
Post Partisan
Post Partisan

Sum with condition

Hi Guys,

 

I have a question for you.

I want to sum a column which has number figure if in the other coloums has a date value.

 

for instance, i have a table like below.

I want to show accumulative line for start and finish. 

 

LineStart

Finish

142020/11/09 
232020/11/102020/12/05
342020/11/112020/12/05
5  
62020/11/092020/12/05
722020/12/05 
5  
22020/12/012020/12/05
352020/12/032020/12/05

 

I tried the code below to get what i want but this one sums up all Line column figures.


Actul IRN date =

VAR _End = CALCULATE ( MAX ( 'SPARES - PO STATUS'[ACTUAL IRN DATE] ), ALL ( 'calendar' ),USERELATIONSHIP('SPARES - PO STATUS'[ACTUAL IRN DATE],'Calendar'[Date]))

RETURN

    IF (

        _End < MIN ( 'calendar'[Date] )|| isblank(MAX ( 'SPARES - PO STATUS'[CDD] )),

        BLANK (),

CALCULATE(

    Sum('SPARES - PO STATUS'[PO_LINE_QUANTITY]), USERELATIONSHIP('SPARES - PO STATUS'[ACTUAL IRN DATE],'calendar'[Date]),

    FILTER(

        ALLSELECTED('calendar'[Date]),

        ('calendar'[Date] <= MAX('calendar'[Date])))))
 
any advices would be appreciated.
 
Regards,
CL
5 REPLIES 5
v-zhenbw-msft
Community Support
Community Support

Hi @colourfullife ,

 

Do you mean that you have four columns in one table?

What is the structure of your table? Could you please provide a mockup sample based on fake data?

It will be helpful if you can show us the exact expected result based on the tables.

 

Please upload your files to OneDrive For Business and share the link here. Please don't contain any Confidential Information or Real data in your reply.

 

Best regards,

 

Community Support Team _ zhenbw

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

v-zhenbw-msft
Community Support
Community Support

Hi @colourfullife ,

 

Do you want to calculate the accumulative line like this following screenshots?

 

sum1.jpg

 

If yes, we can create two measures to meet your requirement.

 

Measure = CALCULATE(SUM('Table'[Line]),FILTER('Table','Table'[Start]=MAX('Date'[Date])))+0

 

Measure 2 = 
SUMX(FILTER(ALL('Date'),'Date'[Date]<=MAX('Date'[Date])),[Measure])

 

sum2.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

HI @v-zhenbw-msft 

Yes, that's what i want to create.

 

I have 4 date columns to show in a line graph.

But all lines start and end in same dates which is not corret.

do you know how make line start as the date value start and ends?

 

Regards,

CL

Regards,

CL 

amitchandak
Super User
Super User
AllisonKennedy
Super User
Super User

@colourfullife Sorry, I don't understand what your sample data relates to in the sample formula - there is no reference to [Line], [Start] or [End] columns? Can you provide a sample output of what you want and describe why the formula you have tried/posted does not work?


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.