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! Request now

Reply
Anonymous
Not applicable

Calculating Average and Sum in one DAX measure based on column value

Hi All,

Appreciaet your help as I am trying to have one DAX measures which will calculate average or sum based on another column value. for headcount i need average for last two months and for sales and profit i need sum for last two months. 
how can i have measure which will give em the values given in the Expected results columns.

 

Zubairkh_0-1639720841298.png

Thanks in advance,

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

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

 

Picture1.png

 

Expected result: =
VAR currentmetrictable =
FILTER ( ALL ( Data ), Data[Metric] = MAX ( Data[Metric] ) )
RETURN
SWITCH (
TRUE (),
SELECTEDVALUE ( Data[Index] ) = 7
&& SELECTEDVALUE ( 'Month'[Index] ) = 7,
IF (
SELECTEDVALUE ( Data[Metric] ) = "Head count",
AVERAGEX ( currentmetrictable, Data[Values] ),
SUMX ( currentmetrictable, Data[Values] )
)
)

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.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

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

 

Picture1.png

 

Expected result: =
VAR currentmetrictable =
FILTER ( ALL ( Data ), Data[Metric] = MAX ( Data[Metric] ) )
RETURN
SWITCH (
TRUE (),
SELECTEDVALUE ( Data[Index] ) = 7
&& SELECTEDVALUE ( 'Month'[Index] ) = 7,
IF (
SELECTEDVALUE ( Data[Metric] ) = "Head count",
AVERAGEX ( currentmetrictable, Data[Values] ),
SUMX ( currentmetrictable, Data[Values] )
)
)

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 @Jihwan_Kim Thanks this really helped where I have dates filter on the visual and I will accept as  a solution.
What if (in another scenraio) I want to ignore the dates/date table reference in the Expected result measure and rather want to have an average values where metric is headcount and I want sum of Values where metric on the row is Sales and Profit? I want to get the values in the expected result column by using VAR in DAX. Please help, example is given below.

Zubairkh_0-1639828373930.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.