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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
wpf_
Post Prodigy
Post Prodigy

How to build a matrix using a measure (not a field) as a value?

So i have created a matrix before populating fields from a table.  But I feel the matrix I need to build is a different circumstance.  It uses the fields as the row and column, but the value I need a measure for it.  I tried it but the value is coming back wrong.  

 

I have:   AvgSpeed = CALCULATE(AVERAGE(TableA[SPEED]), TableB[ID]=1234))  but it shows the same avg speed for every hour and for all locations. 

 

Here are diagrams that might better explain what I have and what I need in the matrix:

Table A and B have relationship using ID as primary. 

 

 

TableAB.PNG

 

So with a matrix I want to show avg speed (value) of each month, each hour, for each location.  Furthermore, the avg speeds are filtered by direction (northbound, southbound).  

Matrix.PNG

 

Hope someone can help. Thanks.

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @wpf_,

You can try to use the following measure formula if it suitable for your scenario:

 

AvgSpeed =
CALCULATE (
    AVERAGE ( TA[SPEED] ),
    ALLSELECTED ( TA ),
    VALUES ( TA[Date] ),
    VALUES ( TA[Hour] ),
    VALUES ( TB[Location] ),
    VALUES ( TB[Direction] )
)

 

If above not help, please share some dummy data with the expected result to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

Hi @wpf_,

You can try to use the following measure formula if it suitable for your scenario:

 

AvgSpeed =
CALCULATE (
    AVERAGE ( TA[SPEED] ),
    ALLSELECTED ( TA ),
    VALUES ( TA[Date] ),
    VALUES ( TA[Hour] ),
    VALUES ( TB[Location] ),
    VALUES ( TB[Direction] )
)

 

If above not help, please share some dummy data with the expected result to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft ,

 

That worked! thank you.  

 

Even thought it worked i am still having a hard time understanding it.  I will need to read up on dax from the ground up.  Can you explain to me step by step what your expression do?  I have a feeling calculate is a transition context?  So AVERAGE gets me the avg of the column i want.  What does ALLSELECTED and VALUES do?  Thanks. 

 

AvgSpeed =
CALCULATE (
    AVERAGE ( TA[SPEED] ),
    ALLSELECTED ( TA ),
    VALUES ( TA[Date] ),
    VALUES ( TA[Hour] ),
    VALUES ( TB[Location] ),
    VALUES ( TB[Direction] )
)

 

Hi @wpf_,

If you are interested in these functions, you can take a look at the following blog of these function usages:

The definitive guide to ALLSELECTED 

DAX – The Many Faces of VALUES() 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
mahoneypat
Employee
Employee

You should be able to do the following to get your desired result.

 

1.  Make a relationship between A and B (Many:1) on the ID column

2. Add a calculated column to TableA for the Month with this  Month = FORMAT(TableA[Date], "mmmm")

3. Make a Matrix visual with Month and Hour columns in the rows and the Direction column in the column field well

4. Make a measure like this    AverageSpeed = AVERAGE(TableA[Speed])   and put it in the Values area

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat ,

 

I tried that but it's showing the same value for each hour.  

 

wpf__0-1594388587475.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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