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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
RobertoSantos83
Frequent Visitor

Dax Issue for revenue

Hi,

I have a column of total revenue, and from that, I need the sum of the revenue for only the paid nights, which are populating based on the date range that we selected.

For example, the selected date range is 01/08/2023–31/08/2023. The arrival date is June 8, 2023, and the departure date is September 30, 2023, and the paid nights are 31 because the date range we set is only August.

Now the total revenue is for all the nights (114), but I need the sum of revenue for only 31 nights as they fall in the date range we selected.

I need to show the sum of revenue for paid nights from the total revenue.

Note:The revenue for each night is different.

How can I achieve this? Please help me.

 

RobertoSantos83_0-1695742636755.png

Paid Night Measure=

VAR startdate =
    MIN ( 'Calendar'[Date] )
VAR enddate =
    MAX ( 'Calendar'[Date] )
VAR ArrivalDate =
    SELECTEDVALUE ( 'RevenueforStays'[ArrivalDate])
VAR DepartureDate =
    SELECTEDVALUE ( 'RevenueforStays'[DepartureDate] )
VAR AdjustedArrivalDate =
    IF ( ArrivalDate < startdate, startdate, ArrivalDate )
VAR AdjustedDepartureDate =
    IF ( DepartureDate > enddate, enddate, DepartureDate )
VAR Result =
 
    SWITCH (
        TRUE (),
        AdjustedArrivalDate <= AdjustedDepartureDate
            && DepartureDate > enddate, DATEDIFF ( AdjustedArrivalDate, AdjustedDepartureDate, DAY ) + 1,
        AdjustedArrivalDate <=AdjustedDepartureDate, DATEDIFF ( AdjustedArrivalDate, AdjustedDepartureDate, DAY )
    )
RETURN
    Result

 

 

 

 

1 REPLY 1
amitchandak
Super User
Super User

@RobertoSantos83 , check if this option can help

 

Between Dates - Dates between
Measure way
Power BI Dax Measure- Allocate data between Range: https://youtu.be/O653vwLTUzM


Tables way
https://amitchandak.mediumcom/dax-get-all-dates-between-the-start-and-end-date-8f3dac4ff90b
https://amitchandak.medium.com/power-query-get-all-dates-between-the-start-and-end-date-9ad6a84cf5f2

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.