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
Christann
Helper IV
Helper IV

How can I get a measure which multiplies columns from several related tables?

How can I create a measure which calculates my total Revenue? I have a table "RoomAssignments" which is related to the table "RoomRates" by a column "Rate Code". I am trying to create a measure which will multiply a count of the rows in RoomAssignments with the corresponding rate in RoomRates. Here is a screenshot of the relationship:

 

related.JPG

 

 

 

I tried: Total Revenue = COUNT(RoomAssignments[RateCode])*RELATED(Rate)

And got:

 

related f 1.JPG

 

 

Then I tried: Total Revenue = COUNT(RoomAssignments[RateCode])*RELATED(RoomRates[Rate])

And got:

 

related f 2.JPG

 

 

What am I doing wrong here?

Thanks in advance for your help!

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

@Christann I created the first 3 columns in RoomAssignment Table & Data is the calculated table. 

 

Rooms Sold Per RateCode = CALCULATE(DISTINCTCOUNT(RoomAssignment[RoomID]), ALLEXCEPT(RoomAssignment,RoomAssignment[RateCode]))
Rate = RELATED(RoomRates[Rate])
Total Sales Per RateCode = RoomAssignment[Rate]*RoomAssignment[Rooms Sold Per RateCode]

 

 

Data = DISTINCT(SELECTCOLUMNS(RoomAssignment,"Rate Code",RoomAssignment[RateCode],"Rate",RoomAssignment[Rate],"Rooms Sold",RoomAssignment[Rooms Sold Per RateCode],"Total Sales",RoomAssignment[Total Sales Per RateCode]))

 

View solution in original post

Anonymous
Not applicable

@Christann Instead of distinctcount just use count. 

View solution in original post

11 REPLIES 11
Anonymous
Not applicable

@Christann 

Create the following columns

1) Rate = Related(Rate)

2) CountofRooms = CALCULATE(DistinctCount(RoomId), ALLEXCEPT(RateCode))

3) Create a calculatetable = DISTINCT(RateCode, Rate, CountofRooms)

4) Final Calculation CALCULATE(SUMX(Rate*CountofRooms))

Is there a way to do this with only a measure?

 

I tried your solution, and got this error:

 

Count of Rooms.JPG

 

Also, would it work better to insert a calculated column into the RoomRates table instead of creating a calculated table?

Thanks so much for your help!

Anonymous
Not applicable

@Christann yeah I think you can do the last step without a table, you would just need to create a distinct filter. 

 

If you post in the power bi file its easier to provide a solution. 

Here is a link to a file containing the data.

Anonymous
Not applicable

@Christann I created the first 3 columns in RoomAssignment Table & Data is the calculated table. 

 

Rooms Sold Per RateCode = CALCULATE(DISTINCTCOUNT(RoomAssignment[RoomID]), ALLEXCEPT(RoomAssignment,RoomAssignment[RateCode]))
Rate = RELATED(RoomRates[Rate])
Total Sales Per RateCode = RoomAssignment[Rate]*RoomAssignment[Rooms Sold Per RateCode]

 

 

Data = DISTINCT(SELECTCOLUMNS(RoomAssignment,"Rate Code",RoomAssignment[RateCode],"Rate",RoomAssignment[Rate],"Rooms Sold",RoomAssignment[Rooms Sold Per RateCode],"Total Sales",RoomAssignment[Total Sales Per RateCode]))

 

It looks to me as if this solution does not take into account the fact that each room is let out several times. For instance, There are 7 "W" rooms and the Rooms Sold per RateCode only takes into account each room once, thus giving the result 7 when the actual answer is 561. How would I fix this?

Anonymous
Not applicable

@Christann Instead of distinctcount just use count. 

Anonymous
Not applicable

Your all except syntax is wrong. Check the below post for syntax.

 

https://msdn.microsoft.com/en-us/query-bi/dax/allexcept-function-dax

v-danhe-msft
Employee
Employee

Hi @Christann,

I could not see the picture you have posted in your probem, could you mind uploading your pictures again or share the pbix file if possible?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I have Edited the post and re-entered my screenshots. Tell me if they don't show up for you.

Hi @Christann,

You could try this measure:

Measure = CALCULATE(COUNT(RoomAssignment[RateCode]),FILTER('RoomAssignment','RoomAssignment'[RateCode]=MAX('RoomRates'[RateCode])))*CALCULATE(SUM(RoomRates[Rate]))

Result:

2.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/u8e34tqk4zei965/How%20can%20I%20get%20a%20measure%20which%20multiplies%20c...

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

Top Solution Authors