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
abhishekrws01
Helper I
Helper I

Calculate revenue base on Start and End Date price

Hello,

 

I am looking for some help. 

 

I have the following two tables:

 

1. Unit - No of units sold by day

2. Price - Price per unit with Start and End date

 

I want to calculate the revenue by creating/summarizing a table called "OutPut", where I can see the Unit, Price and Revenue by day.

 

abhishekrws01_0-1710784044303.png

 

Please help if possible.

Thanks

 

 

2 ACCEPTED SOLUTIONS
kpost
Super User
Super User

No idea if this is the best way BUT it absolutely would work:

 

In Power Query, create a table that looks like this, using the starting and ending values from your original table shown in your question.

 

price_by_day.PNG

 

Here's the .pbix file with the steps :  https://files.catbox.moe/ye4rep.pbix

 

but most of the 'magic' is this custom column that generates all the dates between the ending and starting dates:


let
Dates = {Number.From([Start Date]) .. Number.From([End Date])},
As_Date =
List.Transform(Dates, each Date.From(_))
in
As_Date

 

 

then you just expand the column and voila you have a table of prices by date.

 

 

 

Then once you have this, you basically have a nice lookup table of price by date.  So create a connection between this table and your other tables in such a way that you can use a dax formula like

CALCULATE (SUMX(price * units), RELATEDTABLE(  etc etc   )

 

or something like that....

 

 

 

 

//Mediocre Power BI Advice,  but it's free//

 

View solution in original post

v-yilong-msft
Community Support
Community Support

Hi @abhishekrws01 ,

I create two tables as you mentioned.

vyilongmsft_0-1710821909020.png

vyilongmsft_1-1710821945414.png

Then I create a measure named Price  in Unit_Table.

Price =
CALCULATE (
    MAX ( 'Price_table'[Price] ),
    FILTER (
        'Price_table',
        SELECTEDVALUE ( 'Unit_Table'[Date] ) >= 'Price_table'[Start_Date]
            && SELECTEDVALUE ( 'Unit_Table'[Date] ) <= 'Price_table'[End_Date]
    )
)

vyilongmsft_3-1710822083263.png

Then I create another measure named Revenue.

Revenue = SUM( Unit_Table[Units]) * 'Unit_Table'[Price]

Finally you will get the OutPut you want.

vyilongmsft_4-1710822229287.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
abhishekrws01
Helper I
Helper I

Thank you.. This one also works. I guess it will take more space in the model.

v-yilong-msft
Community Support
Community Support

Hi @abhishekrws01 ,

I create two tables as you mentioned.

vyilongmsft_0-1710821909020.png

vyilongmsft_1-1710821945414.png

Then I create a measure named Price  in Unit_Table.

Price =
CALCULATE (
    MAX ( 'Price_table'[Price] ),
    FILTER (
        'Price_table',
        SELECTEDVALUE ( 'Unit_Table'[Date] ) >= 'Price_table'[Start_Date]
            && SELECTEDVALUE ( 'Unit_Table'[Date] ) <= 'Price_table'[End_Date]
    )
)

vyilongmsft_3-1710822083263.png

Then I create another measure named Revenue.

Revenue = SUM( Unit_Table[Units]) * 'Unit_Table'[Price]

Finally you will get the OutPut you want.

vyilongmsft_4-1710822229287.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thank you very much.. it works

kpost
Super User
Super User

No idea if this is the best way BUT it absolutely would work:

 

In Power Query, create a table that looks like this, using the starting and ending values from your original table shown in your question.

 

price_by_day.PNG

 

Here's the .pbix file with the steps :  https://files.catbox.moe/ye4rep.pbix

 

but most of the 'magic' is this custom column that generates all the dates between the ending and starting dates:


let
Dates = {Number.From([Start Date]) .. Number.From([End Date])},
As_Date =
List.Transform(Dates, each Date.From(_))
in
As_Date

 

 

then you just expand the column and voila you have a table of prices by date.

 

 

 

Then once you have this, you basically have a nice lookup table of price by date.  So create a connection between this table and your other tables in such a way that you can use a dax formula like

CALCULATE (SUMX(price * units), RELATEDTABLE(  etc etc   )

 

or something like that....

 

 

 

 

//Mediocre Power BI Advice,  but it's free//

 

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.