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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

DAX Divide in a Measure with Variables

Hello.

I would like some help with regards to the following %NS measure. %NS measure is a division of Accounts Value per Netsales. I want to create the first table and instead I am getting the second.  The %NS for GMI is calculated correctly but appears only under Total and in the GMI row I am getting 0%. Please find below the measure that I have created. Any advice will be really appreciated. Thanks in advance.

Result.PNG

%NS PER =

VAR Netsales=  CALCULATE (

                SUMX(Table;Table[Value]);

                FILTER(Table;Table[Account]="Net Sales");REMOVEFILTERS(Table[Account]))

 

Var GMI= CALCULATE (

                SUMX(Table;Table[Value]);

                FILTER(Table;Table[Account]="GMI");REMOVEFILTERS(Table[Account]))

 

RETURN

DIVIDE(GMI;Netsales;0)

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1674218352588.png

 

Actuals measure: = 
SUM( 'Table'[Actuals] )

 

Percent Netsales: =
VAR _netsales =
    CALCULATE (
        [Actuals measure:],
        FILTER ( ALL ( 'Table' ), 'Table'[Account] = "Netsales" )
    )
VAR _actuals = [Actuals measure:]
RETURN
    IF ( HASONEVALUE ( 'Table'[Account] ), DIVIDE ( _actuals, _netsales ) )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Hi, Thanks for the answer but it is not working for my model. I have simplified it and provided only one table but I have a Date table and Account as well that are connected with my Table. I have tried to adapt your solution and instead of ALL, used ALLSELECTED as I want my table to get updated according to user selection-filters on Info (monthly values or not), Year and Month. As you can see below the problem is now that is working only for Netsales and not for the rest Accounts. Moreover, in contrast with your Netsales my Netsales are only being calculated for Account =Netsales but wanted to get the same Netsales value in all rows. I have attached my new variable along with the result that it brings back. Any help will be much appreciated.

 

Result2.PNG

%NS PER =
VAR Netsales=  CALCULATE (
                [Actuals PER];
               ALLSELECTED(Table[Info];Table[Month];Table[Year]);filter(Table;Table[Account]="Net Sales"))

VAR _actuals=[Actuals PER]
RETURN
    IF ( HASONEVALUE ( Table[Account] );DIVIDE(_actuals;Netsales))

Hi,

Please share your pbix file's link, and then I can try to look into it.

Thanks.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
amitchandak
Super User
Super User

@Anonymous , try like

 

%NS PER =

VAR Netsales= CALCULATE (

SUMX(Table;Table[Value]);

FILTER(all(Table[Account]) ;Table[Account]="Net Sales"))

 

Var GMI= CALCULATE (

SUMX(Table;Table[Value]);

FILTER(all(Table[Account]);Table[Account]="GMI"))
RETURN

DIVIDE(GMI;Netsales;0)

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors