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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sima_ue031
Helper I
Helper I

Problem with DAX measures - total

Hello, 

 

i have a problem with 2 same measures.

My casse is to count customers between 0-5% of % of grand total, and 5-10% of grand total

 

My code for 0-5% :

Broj kupaca 0-5 = 

VAR _tabela = ADDCOLUMNS(
    SUMMARIZE(
        OTP,
        OTP[Šifra kupca]
    ),
    "@Promet",[Promet],
    "@UkupanPromet",CALCULATE([Promet],REMOVEFILTERS(OTP[Šifra kupca]))
)

VAR _ucesce = ADDCOLUMNS(
    _tabela,
    "@Ucesce",DIVIDE([@Promet],[@UkupanPromet])
)

VAR _filtrirano = FILTER(
    _ucesce,
    [@Ucesce] >=0.00 && [@Ucesce]<=0.05
)

VAR _brojKupaca = COUNTROWS(_filtrirano)

RETURN _brojKupaca

 

and my code for 5-10% : 

Broj kupaca 5-10 = 

VAR _tabela = ADDCOLUMNS(
    SUMMARIZE(
        OTP,
        OTP[Šifra kupca]
    ),
    "@Promet",[Promet],
    "@UkupanPromet",CALCULATE([Promet],REMOVEFILTERS(OTP[Šifra kupca]))
)

VAR _ucesce = ADDCOLUMNS(
    _tabela,
    "@Ucesce",DIVIDE([@Promet],[@UkupanPromet])
)

VAR _filtrirano = FILTER(
    _ucesce,
    [@Ucesce] >=0.051 && [@Ucesce]<=0.10
)

VAR _brojKupaca = COUNTROWS(_filtrirano)

RETURN _brojKupaca

 

 

 

Now i will attach my photo : 

 

sima_ue031_0-1737379019075.png

 

in green are customers from 0-5%, and pink 5-10%

Values are correct, but for second formula i dont have a total. You can see at my image. 

Where is the problem?

3 REPLIES 3
bhanu_gautam
Super User
Super User

@sima_ue031 To ensure that the total is calculated correctly, you can use the SUMX function to iterate over the table and sum the results. Here is how you can modify your measures:

Broj kupaca 0-5 =
VAR _tabela = ADDCOLUMNS(
SUMMARIZE(
OTP,
OTP[Šifra kupca]
),
"@Promet",[Promet],
"@UkupanPromet",CALCULATE([Promet],REMOVEFILTERS(OTP[Šifra kupca]))
)

VAR _ucesce = ADDCOLUMNS(
_tabela,
"@Ucesce",DIVIDE([@Promet],[@UkupanPromet])
)

VAR _filtrirano = FILTER(
_ucesce,
[@Ucesce] >=0.00 && [@Ucesce]<=0.05
)

VAR _brojKupaca = COUNTROWS(_filtrirano)

RETURN
IF(
HASONEVALUE(OTP[Šifra kupca]),
_brojKupaca,
SUMX(
VALUES(OTP[Šifra kupca]),
CALCULATE(_brojKupaca)
)
)

 

DAX
Broj kupaca 5-10 =
VAR _tabela = ADDCOLUMNS(
SUMMARIZE(
OTP,
OTP[Šifra kupca]
),
"@Promet",[Promet],
"@UkupanPromet",CALCULATE([Promet],REMOVEFILTERS(OTP[Šifra kupca]))
)

VAR _ucesce = ADDCOLUMNS(
_tabela,
"@Ucesce",DIVIDE([@Promet],[@UkupanPromet])
)

VAR _filtrirano = FILTER(
_ucesce,
[@Ucesce] >=0.051 && [@Ucesce]<=0.10
)

VAR _brojKupaca = COUNTROWS(_filtrirano)

RETURN
IF(
HASONEVALUE(OTP[Šifra kupca]),
_brojKupaca,
SUMX(
VALUES(OTP[Šifra kupca]),
CALCULATE(_brojKupaca)
)
)




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

Proud to be a Super User!




LinkedIn






@bhanu_gautam 

Look this. 
When I filter Naziv column, i got i totals : 

sima_ue031_0-1737497396282.png


But when not filtering , i got blank : 

sima_ue031_1-1737497415110.png

 





@bhanu_gautam My table filter i want to be a dinamicly. In this case filter is Naziv ( Category) but somethimes i want to put a ItemNo or something. And IF Hasonevalue not work propertly in other cases

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.