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! Request now

Reply
RogerSteinberg
Post Patron
Post Patron

Sum Distinct values by Month

Hi,

 

I am trying to sum the cost column by StartMonth. The issue is that my cost can be duplicated for a Product if there are multiple End Dates. For example, in row 2 and 3, the cost is just 10$ NOT 20$.

 

Start                End               Cost   Product

2020-01-01    5   A
2020-01-01 2020-02-01   10   B
2020-01-01  2020-03-01   10   B
2020-01-01  2020-02-01   15   C
2020-01-01  2020-03-01   15   C
2020-02-01  2020-05-01   30   D
2020-02-01  2020-06-01   30   D
2020-02-01  2020-05-01   50   E
2020-02-01  2020-06-01   50    E
2020-02-01  100   F

 

The final output should look something like this:

Start   Cost
1/1/2020   30
2/1/2020  180

 

For January: Product A (5$), Product B (10$), Product C (15$)

For February: Product D (30$), Product E (50$), Product F (100$)

 

I tried this formula and almost works but it's not able to sum the rows with Blank End Dates. How can I make sure it takes them into account?:

 

Cost By YearMonth = 
CALCULATE(
    SUM('Fact'[Cost]),
    ALLEXCEPT(
        'Fact',
        'Fact'[Start],
        'Fact'[End]
    ))

 

Note: I need a calculated column NOT a measure

 

 

1 ACCEPTED SOLUTION

Here is a column expression that works, although you should consider doing this either as a measure or in the query editor with a Group By step.

 

Cost by YearMonth =
CALCULATE (
SUMX ( VALUES ( 'Fact'[Product] ), CALCULATE ( AVERAGE ( 'Fact'[Cost] ) ) ),
ALLEXCEPT ( 'Fact', 'Fact'[Start] )
)

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@RogerSteinberg ,

Try sumx(summarize(Table, Table[Start],Table[Product],"_1",max(Table[Cost])),[_1])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I need a calculated column

Here is a column expression that works, although you should consider doing this either as a measure or in the query editor with a Group By step.

 

Cost by YearMonth =
CALCULATE (
SUMX ( VALUES ( 'Fact'[Product] ), CALCULATE ( AVERAGE ( 'Fact'[Cost] ) ) ),
ALLEXCEPT ( 'Fact', 'Fact'[Start] )
)

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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