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
shaik51
Frequent Visitor

I want to do calculations on values in the same column

HI,this is the existing dax for the below table:

SUMX('table1', DIVIDE('table1'[WTD] * [VOL], SUM('table1'[VOL])))
IDWTDVOL
16733
25544
36655
47866
how can i acheive the same result or write same dax as above for the below new table2 without unpivoting the table and also how can i find MAX(WTD).
IDPFvalues
1WTD67
2WTD55
3WTD66
4WTD78
1VOL33
2VOL44
3VOL55
4VOL66

 Any Help would be appreciated,Thanks.

 @amitchandak @tamerj1 @FreemanZ @johnt75 @wdx223_Daniel @Greg_Deckler

14 REPLIES 14
wdx223_Daniel
Super User
Super User

just for the data you provided,

Measure=SUMX(VALUES('table1'[ID]),DIVIDE(CALCULATE(PRODUCTX('table1','table1'[values])),CALCULATE(SUM('table1'[values]),ALLSELECTED('table1'[ID]))))

HI @wdx223_Daniel ,there are other values also in the PF column like VAL,UNITS etc,,but I need calulation on VOL and WTD out of all values in PF column. 

if each ID always has one WTD and one VOL then try this

Measure=SUMX(VALUES('table1'[ID]),DIVIDE(CALCULATE(PRODUCTX(FILTER('table1','table1'[PF] IN {"WTD","VOL"}),'table1'[values])),CALCULATE(SUM('table1'[values]),ALLSELECTED('table1'[ID]))))

tamerj1
Super User
Super User

Hi @shaik51 

how do we know which WTD row match with which VAL row? Do we have to match a date or index column? 

Hi,there is an ID column

thanks

 

@shaik51 

Please try

Result =
SUMX (
GENERATE (
VALUES ( 'Table'[ID] ),
VAR T =
CALCULATETABLE ( 'Table' )
VAR WTD =
MAXX ( FILTER ( T, 'Table'[PF] = "WTD" ), 'Table'[Value] )
VAR VOL =
MAXX ( FILTER ( T, 'Table'[PF] = "VOL" ), 'Table'[Value] )
RETURN
ROW ( "WTD", WTD, "VOL", VOL )
),
[WTD] * [VOL]
)

showing error as The syntax for ',' is incorrect. (DAX(SUMX (GENERATE (VALUES ( 'VM MarketShare'[VM Product Key] ),VAR T =CALCULATETABLE ( 'VM MarketShare' )VAR WSD =MAXX ( FILTER ( T, 'VM MarketShare'[FACT_ALIAS] = "WTD" ), 'VM MarketShare'[VALUE] )VAR VOL =MAXX ( FILTER ( T, 'VM MarketShare'[FACT_ALIAS] = "VOLUME" ), 'VM MarketShare'[VALUE] )RETURNROW ( "WTD", WTD, "VOLUME", VOL )),[WSD] * [VOL] ))).

 

@shaik51 

Result =
SUMX (
GENERATE (
VALUES ( 'VM MarketShare'[VM Product Key] ),
VAR T =
CALCULATETABLE ( 'VM MarketShare' )
VAR WSD =
MAXX (
FILTER ( T, 'VM MarketShare'[FACT_ALIAS] = "WTD" ),
'VM MarketShare'[VALUE]
)
VAR VOL =
MAXX (
FILTER ( T, 'VM MarketShare'[FACT_ALIAS] = "VOLUME" ),
'VM MarketShare'[VALUE]
)
RETURN
ROW ( "WTD", WTD, "VOLUME", VOL )
),
[WSD] * [VOL]
)

HI @tamerj1 ,Thanks for the quick reply and solution,the measure you have sent is working but it is showing different result values in the visual when compared to the old measure,can you help me on this.

@shaik51 
Yes you are right

I missed the DIVIDE part. Yet I still have some doubts regarding which result are you expectiong at the grand total level. Please refer to the attached sample file and let me know.

1.png

Result = 
SUMX (
    GENERATE (
        VALUES ( 'VM MarketShare'[VM Product Key] ),
        VAR T =
            CALCULATETABLE ( 'VM MarketShare' )
        VAR _WTD =
            MAXX (
                FILTER ( T, 'VM MarketShare'[FACT_ALIAS] = "WTD" ),
                'VM MarketShare'[VALUE]
            )
        VAR VOL =
            MAXX (
                FILTER ( T, 'VM MarketShare'[FACT_ALIAS] = "VOLUME" ),
                'VM MarketShare'[VALUE]
            )
        RETURN
            ROW ( "WTD", _WTD, "VOLUME", VOL )
    ),
    DIVIDE ( [WTD] * [VOLUME], [VOLUME] )
)
Result 2 = 
AVERAGEX (
    GENERATE (
        VALUES ( 'VM MarketShare'[VM Product Key] ),
        VAR T =
            CALCULATETABLE ( 'VM MarketShare' )
        VAR _WTD =
            MAXX (
                FILTER ( T, 'VM MarketShare'[FACT_ALIAS] = "WTD" ),
                'VM MarketShare'[VALUE]
            )
        VAR VOL =
            MAXX (
                FILTER ( T, 'VM MarketShare'[FACT_ALIAS] = "VOLUME" ),
                'VM MarketShare'[VALUE]
            )
        RETURN
            ROW ( "WTD", _WTD, "VOLUME", VOL )
    ),
    DIVIDE ( [WTD] * [VOLUME], [VOLUME] )
)

Hi, the above measure is giving wrong values,,like it is showing sum of vaues in the visual.

HI,there is another ID column with Unique ids,,i just posted a sample of original data,,we can take that column as [ID] for example

IDPFvalues
1WTD4
2WTD6
3WTD5
4WTD6
1VOL7
2VOL8
3VOL2
4VOL6

thanks.

 

FreemanZ
Super User
Super User

hi @shaik51 

can you paste your expected result based on table2?

Hi, I want to achieve the same result of the first dax expression written for table1 for table2,,I want to write a measure that multiplies each WTD value with each VAL value from [value] column and divide it with total sum of VAL from [value] column from the table 2.  and also a measure to find MAX of WTD from table2.

Thanks.

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