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
gclements
Helper II
Helper II

SUMX Over Distinct and Max

Hi,

 

I have a denormalised header and detail fact table.  The header table contains channels per CLI per Billing Period and are non-addiditve across the same CLI as they represent the number of channels at a point in time.  The channels are also duplicated across the ChargeID.  I need to SUM the channels taking Distinct CLI and MAX Billing Period, see the table below.  The channels are currently totaling 180 but they need to total 60.

 

I should also mention that this table can contain millions of records so ideally I need the most efficient solution.

I feel like I need to create a table expression containing Distinct CLI, Max Billing Period, Max Connections and then SUMX over that but not sure how.

 

Any help is greatly appreciated.

CLI BillingPeriodCharge IDChannelsCostCorrect Channels
07700000012 202101110£5.00 
07700000012 202101210£3.00 
07700000012 202102320£4.00 
07700000012 202102420£3.0020
07700000013 202101530£7.00 
07700000013 202102620£4.00 
07700000013 202102720£5.0020
07700000014 202102810£5.00 
07700000014 202102910£3.0010
07700000015 2021011010£3.00 
07700000015 2021011110£2.00 
07700000015 2021011210£2.0010
   180£46.0060
1 ACCEPTED SOLUTION
gclements
Helper II
Helper II

Thanks for the replies but unfortunately they were not working for me.
I have managed to solve it using the following measure:

Channels Total = 
SUMX( 
    VALUES ( Charges[CLI] ), 
    CALCULATE (
        CALCULATE (
            MAX ( Charges[Channels] ),
            FILTER (
                VALUES ( Charges[BillingPeriod] ),
                Charges[BillingPeriod] = MAX ( Charges[BillingPeriod] )
            )
        )
    )
)

 

I have updated the sample project to reflect this:

https://1drv.ms/u/s!AoTVsSI4n62qjZ0Mq4u-5-4lAzqDqw?e=mYde5a

 

If anyone know a more efficient way to right this then I would love to hear.

Also I'm not sure why I had to use CALCULATE twice but it was the only way I could include part of the code without having to create a seperate measure. 

If anyone has a good explanation for this then please let me know.

View solution in original post

6 REPLIES 6
gclements
Helper II
Helper II

Thanks for the replies but unfortunately they were not working for me.
I have managed to solve it using the following measure:

Channels Total = 
SUMX( 
    VALUES ( Charges[CLI] ), 
    CALCULATE (
        CALCULATE (
            MAX ( Charges[Channels] ),
            FILTER (
                VALUES ( Charges[BillingPeriod] ),
                Charges[BillingPeriod] = MAX ( Charges[BillingPeriod] )
            )
        )
    )
)

 

I have updated the sample project to reflect this:

https://1drv.ms/u/s!AoTVsSI4n62qjZ0Mq4u-5-4lAzqDqw?e=mYde5a

 

If anyone know a more efficient way to right this then I would love to hear.

Also I'm not sure why I had to use CALCULATE twice but it was the only way I could include part of the code without having to create a seperate measure. 

If anyone has a good explanation for this then please let me know.

ryan_mayu
Super User
Super User

@gclements 

maybe you can try

Measure = sumx(VALUES(Charges[CLI]),[SumMaxBP])




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Tahreem24
Super User
Super User

@gclements ,

Try this measure:

Measure =
VAR Answer_ = CALCULATE(MAX('Table'[Charge ID]),ALLEXCEPT('Table','Table'[CLI]))
RETURN CALCULATE(SUM('Table'[Channels]),FILTER('Table','Table'[Charge ID]=Answer_))
 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Thanks for the reponse.  Unfortunately this isn't working for me either as it is not filtering by MAX(BillingPeriod), the MAX(ChargeID) may not necessarily be the latest state of the CLI as data is not always entered chronologically.

I have had a go at this myself and have got so far but cant seem to finalise it.

Please view my power bi project here:

https://1drv.ms/u/s!AoTVsSI4n62qjZ0Mq4u-5-4lAzqDqw?e=mYde5a

 

amitchandak
Super User
Super User

@gclements , Create a measure like

sumx(summarize(Table, Table[CLI], Table[Channels]), [Channels])

 

or

 

sumx(values(Table[CLI]), calculate(Max (Table[Channels])))

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

This doesnt filter on the MAX(Billing Period) so will give the wrong result, such as 07700000013 the most recent channels is 20, not 30 but MAX(Channels) will result in 30.  It needs to be the channels associated with the MAX(Billing Period).

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