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
lolojee
New Member

measures aggregated on different dimensions

 Hi all,

 

I have a table with datein, dateiout two dimensions. I want to create measure1 aggregated on quantity by datein  and measure2 aggregated on price by dateout like the following table.  Any idea for this requirement? Thanks in advanced.

 powerbi.jpg

 

 

 

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @lolojee

 

You can do this using a calendar table which has an active relationship with one of your date columns and an inactive relationship with the other one.

 

Here is an example pbix.

 

You should set up your data model like this:

image.png

 

And write measures like this:

measure1 = 
SUM ( Sales[quantity] )

measure2 = 
CALCULATE (
    SUM ( Sales[price] ),
    USERELATIONSHIP ( Sales[dateout], 'Calendar'[Date] )
)

In this example, the inactive relationship is with the dateout column, so measure2 uses USERELATIONSHIP to active the inactive relationship.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

Assuming that you have a disconnected Calendar table and that you use that Calender table for your year/month column in your visual:

 

measure1 = SUMX(FILTER(ALL('2Dimensions'),MONTH(MAX('Calendar'[Date]))=MONTH([datein])),'2Dimensions'[quantity])

measure2 = SUMX(FILTER(ALL('2Dimensions'),MONTH(MAX('Calendar'[Date]))=MONTH([dateout])),'2Dimensions'[price])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
OwenAuger
Super User
Super User

Hi @lolojee

 

You can do this using a calendar table which has an active relationship with one of your date columns and an inactive relationship with the other one.

 

Here is an example pbix.

 

You should set up your data model like this:

image.png

 

And write measures like this:

measure1 = 
SUM ( Sales[quantity] )

measure2 = 
CALCULATE (
    SUM ( Sales[price] ),
    USERELATIONSHIP ( Sales[dateout], 'Calendar'[Date] )
)

In this example, the inactive relationship is with the dateout column, so measure2 uses USERELATIONSHIP to active the inactive relationship.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

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.