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
Giada_Togliatti
Post Patron
Post Patron

Measure doesn't show value if I use variable

Hi, 

I created a measure with some variable, the measure must show a value if there is something selected, instead it should show %

I've made similar formula with other database and it works, why now it shows always % also if I select something?

The formula is something like this:

masure=
var maxtime= max(field5)
VAR _sel1 =
    COUNTROWS ( ALLSELECTED ( 'field1) )
VAR _sel2 =
    COUNTROWS ( ALLSELECTED ( field2) )
RETURN
    IF (
        sel1 = 1
            &&  sel2= 1,
        CALCULATE (
          MAX(field3),
          [field5]= maxtime
          ),
        "%"
    )
Thank you
8 REPLIES 8
v-alq-msft
Community Support
Community Support

Hi, @Giada_Togliatti 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

 

Table:

e1.png

 

You may create a measure as below.

Mva = 
VAR maxtime= max('Table'[field1])
VAR _sel1 =
COUNTROWS (ALLSELECTED('Table'[field2]) )

VAR _sel2 =
COUNTROWS ( ALLSELECTED('Table'[field3]) )
RETURN
IF (
    _sel1 = 1&& _sel2= 1,
    CALCULATE(
          MAX('Table'[field5]),
          FILTER(
              ALL('Table'),
             'Table'[field4] ="chairs"&&
             'Table'[field1]=maxtime
          )
    ),
    "%"
)

 

Result:

e2.png

 

e3.png

 

Best Regards

Allan

 

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

andre
Memorable Member
Memorable Member

ALLSELECTED does the opposite of what you want to do, if you want to see what's selected, i assume in slicers, then you should just use countrows on your table, whatever it counts, that what has been selected, distinict(columnName) will give you all the distinct values that have been selected

@andre , @Pragati11 , @amitchandak 

I tried to remove allselected but it gives me error, I tried to change allselected with distinct but it doesn't work, I see always %

 

field1field2field3field4field5
201806string1string4chairs5
201906string1string5chairs6
201806string2string6table 9
201906string3string6table7

 field 2 and field3 are used in slicer

I shoud do a formula like this:

mwa=

VAR maxtime=
max(field1)
VAR _sel1 =
COUNTROWS (allslected( field2) )

VAR _sel2 =
COUNTROWS ( allselected( field3) )
RETURN
IF (
_sel1 = 1
&& _sel2= 1,

CALCULATE(max(field5),
[field4]="chairs",
[field1]=maxtime), "%")

Hi, @Giada_Togliatti 

 

If you take the answer of someone, please mark it as the solution to help the other members who have same problems find it more quickly. If not, let me know and I'll try to help you further. Thanks.

 

Best Regards

Allan

amitchandak
Super User
Super User

@Giada_Togliatti , I doubt there some mismatch at [field5]= maxtime

Can you share sample data and sample output in table format?

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Pragati11
Super User
Super User

Hi @Giada_Togliatti ,

 

Just wanted to check why you are using ALLSELECTED in the measure? (highlighted)

masure=
var maxtime= max(field5)
VAR _sel1 =
    COUNTROWS ( ALLSELECTED ( 'field1) )
VAR _sel2 =
    COUNTROWS ( ALLSELECTED ( field2) )
RETURN
    IF (
        sel1 = 1
            &&  sel2= 1,
        CALCULATE (
          MAX(field3),
          [field5]= maxtime
          ),
        "%"
    )
 
Is ALLSELECTED your tablename?
 
Thanks,
Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

@Pragati11, allselected is the dax formula, in other situation it works, after allselected I used tablename(fieldname), I used allselected because I must consider the selection of field1 and field2 that are used in slicer

Hi @Giada_Togliatti ,

 

Try removing ALLSELECTED from your measure with COUNTROWS and test.

If it doesn't work, share some sample pbix file to check for the issue.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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.