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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
MichaelSamiotis
Resolver I
Resolver I

Totals are not correct

Hello all,

I have the below but as you can guess my totals don't agree as my matrix is per shop and per year.

VAR PreviousYearDates = PREVIOUSYEAR ( 'Dim Dates'[Date] )
 
VAR calc =
CALCULATE (
    DISTINCTCOUNT( 'Fact Sales'[customer_id] ),
    LEFT ( 'Fact Sales'[Shop_Code],1 ) = "S",
    PreviousYearDates,
    KEEPFILTERS (
        NOT (
            ISBLANK ( 'Fact Sales'[Shop] )
        )
    )
)
 
I have tried the below but doesn't work:
 
VAR summarisedtable=
    SUMMARIZE('Fact Sales','Fact Sales'[Shop],'Dim Dates'[Year],"Distinct customers per year",calc)
 
RETURN
IF 
    HASONEVALUE(
        'Dim Shop'[Shop]) && HASONEVALUE('Dim Dates'[Year]),
calc,
SUMX(summarisedtable,[Distinct customers per year])

)
 
Can you please help with that? Thank you all!
1 ACCEPTED SOLUTION
MichaelSamiotis
Resolver I
Resolver I

VAR PreviousYearDates = PREVIOUSYEAR ( 'Dim Dates'[Date] )

VAR calc =
CALCULATE (
    DISTINCTCOUNT( 'Fact Sales'[customer_id] ),
    LEFT ( 'Fact Sales'[Shop_Code],1 ) = "S",
    PreviousYearDates,
    KEEPFILTERS (
        NOT (
            ISBLANK ( 'Fact Sales'[Shop] )
        )
    )
)

VAR TotalCalc =
CALCULATE (
    DISTINCTCOUNT( 'Fact Sales'[customer_id] ),
    LEFT ( 'Fact Sales'[Shop_Code],1 ) = "S",
    PreviousYearDates
)

RETURN
IF ( 
    HASONEVALUE('Dim Shop'[Shop]) && HASONEVALUE('Dim Dates'[Year]),
    calc,
    TotalCalc
)

View solution in original post

3 REPLIES 3
MichaelSamiotis
Resolver I
Resolver I

VAR PreviousYearDates = PREVIOUSYEAR ( 'Dim Dates'[Date] )

VAR calc =
CALCULATE (
    DISTINCTCOUNT( 'Fact Sales'[customer_id] ),
    LEFT ( 'Fact Sales'[Shop_Code],1 ) = "S",
    PreviousYearDates,
    KEEPFILTERS (
        NOT (
            ISBLANK ( 'Fact Sales'[Shop] )
        )
    )
)

VAR TotalCalc =
CALCULATE (
    DISTINCTCOUNT( 'Fact Sales'[customer_id] ),
    LEFT ( 'Fact Sales'[Shop_Code],1 ) = "S",
    PreviousYearDates
)

RETURN
IF ( 
    HASONEVALUE('Dim Shop'[Shop]) && HASONEVALUE('Dim Dates'[Year]),
    calc,
    TotalCalc
)
MichaelSamiotis
Resolver I
Resolver I

I tried the above with sumx but doesn't work.

ppm1
Solution Sage
Solution Sage

Please see this article for how to get your expected totals.

(2) Power BI - Tales from the front #01 - Getting the Right Total - YouTube

 

Pat

Microsoft Employee

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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