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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
labuser1235
Helper IV
Helper IV

Rate Per Hour

Hi All,

 

I have two tables here with almost similar kind of data. However when I try to give relations there are two columns which needs to get matched for the end result. Which one to be taken as active and other one as inactive, either ways it goes wrong in the output table. PBIX LINK 

Please help.

 

Table1:

DateFruit NameTypePrice SoldTime taken to sold in min
1/31/2020OrangeType-2768
1/31/2020Apple Type-3834
1/31/2020GrapesType-1212
1/31/2020OrangeType-1565
1/31/2020OrangeType-31028
1/31/2020Apple Type-1315
1/31/2020GrapesType-2495
1/31/2020GrapesType-3647
1/31/2020OrangeType-1532
1/31/2020OrangeType-2712
1/31/2020Apple Type-3816
1/31/2020GrapesType-1224
1/30/2020OrangeType-153
1/30/2020OrangeType-31028
1/30/2020Apple Type-1334
1/30/2020GrapesType-247
1/30/2020GrapesType-3617
1/30/2020OrangeType-1530

 

 

Table2:

Fruit NameTypePrice
OrangeType-15
OrangeType-27
OrangeType-310
AppleType-13
AppleType-25
AppleType-38
GrapesType-12
GrapesType-24
GrapesType-36

 

Output Matrix Table: 

  

Fruit NameTypePriceAvg TimeRate per hour
OrangeType-1 $   5.0032.5 $       9.23
OrangeType-2 $   7.0040 $    10.50
OrangeType-3 $ 10.0028 $    21.43
AppleType-1 $   3.0024.5 $       7.35
AppleType-2 $   5.000 
AppleType-3 $   8.0025 $    19.20
GrapesType-1 $   2.0018 $       6.67
GrapesType-2 $   4.0051 $       4.71
GrapesType-3 $   6.0032 $    11.25
3 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

Please find the calc.

https://www.dropbox.com/s/jgzxsxjlcz3ixmk/RatePerHour.pbix?dl=0

 

Per Hour Rate = DIVIDE(Table2[Price],Table2[Avg Total])*60
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Anonymous
Not applicable

Hi,

 

To get the results, actually you don't need any relationship between the two tables. Delete the relationships.

 

Then add the following calculated columns to your Table 2:

 

AvgTime = AVERAGEX(
            FILTER('Demo data',
                    AND('Demo data'[Fruit Name]='Fruit Price'[Fruit Name],
                                'Demo data'[Type]='Fruit Price'[Type])
            ),'Demo data'[Time taken to sold in min])

 

Rate Per Hour = DIVIDE('Fruit Price'[Price],'Fruit Price'[AvgTime],0)*60

 

This two calculated columns in Table 2 will give you the desire out except for "Apple". Because in one table it is spelt as "Apple" and in the other table it is spelt as "Apple " - with an extra space. Once you correct that spellings in your source table, it will work fine.

 

View solution in original post

vivran22
Community Champion
Community Champion

Hello @labuser1235

 

There are various ways to approach this. Personally, I try to avoid many-to-many relationship (if it is required) in Power BI.

 

Alternate way is to create filter tables with unique values and then create One-to-Many relationship:

 

Capture.JPG

 

I have used DAX to create these two tables:

 

 

 

ftFruit = DISTINCT(dtFruits[Fruit Name])

ftFruit = DISTINCT(dtFruits[Fruit Name])

Created another DAX for Rate/hour

Rate per Hour = DIVIDE(SUM(dtSales[Price Sold]),SUM(dtSales[Time taken to sold in min]))*60

 

Following is the output:

 

Capture2.JPG

 

You may find the solution pbix file here

 

Regards,
Vivek

If it helps, please mark it as a solution

Kudos would be a cherry on the top 🙂

https://www.vivran.in/

 

View solution in original post

6 REPLIES 6
vivran22
Community Champion
Community Champion

Hello @labuser1235

 

There are various ways to approach this. Personally, I try to avoid many-to-many relationship (if it is required) in Power BI.

 

Alternate way is to create filter tables with unique values and then create One-to-Many relationship:

 

Capture.JPG

 

I have used DAX to create these two tables:

 

 

 

ftFruit = DISTINCT(dtFruits[Fruit Name])

ftFruit = DISTINCT(dtFruits[Fruit Name])

Created another DAX for Rate/hour

Rate per Hour = DIVIDE(SUM(dtSales[Price Sold]),SUM(dtSales[Time taken to sold in min]))*60

 

Following is the output:

 

Capture2.JPG

 

You may find the solution pbix file here

 

Regards,
Vivek

If it helps, please mark it as a solution

Kudos would be a cherry on the top 🙂

https://www.vivran.in/

 

Thank you so much @vivran22 . Didn't think to have seperate tables even this method is working. 

Anonymous
Not applicable

Hi,

 

To get the results, actually you don't need any relationship between the two tables. Delete the relationships.

 

Then add the following calculated columns to your Table 2:

 

AvgTime = AVERAGEX(
            FILTER('Demo data',
                    AND('Demo data'[Fruit Name]='Fruit Price'[Fruit Name],
                                'Demo data'[Type]='Fruit Price'[Type])
            ),'Demo data'[Time taken to sold in min])

 

Rate Per Hour = DIVIDE('Fruit Price'[Price],'Fruit Price'[AvgTime],0)*60

 

This two calculated columns in Table 2 will give you the desire out except for "Apple". Because in one table it is spelt as "Apple" and in the other table it is spelt as "Apple " - with an extra space. Once you correct that spellings in your source table, it will work fine.

 

Thank you so much, it worked like charm 🙂

amitchandak
Super User
Super User

Please find the calc.

https://www.dropbox.com/s/jgzxsxjlcz3ixmk/RatePerHour.pbix?dl=0

 

Per Hour Rate = DIVIDE(Table2[Price],Table2[Avg Total])*60
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Awesome worked like charm. Thank you so much 🙂

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.