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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Tezaroyal
Frequent Visitor

Dax issue for In between the date range count

Hi,

 

I wrote below dax query for bookings count for selected date range if the booking (Created and cancelled date)is between the date range it should be 0 and my query working.but in my data there are some duplicates records with different properties for example below is screenshot of two records with same number still both stays are different so we need show both, as my selected date range is 1-1-2021 to 01-07-2023 the record No show should be 0 but its showing 1 and you can see in another screenshot  for other records which doesnt contain duplicates the logic is working fine, is this because of duplicates or anything else please help me

 

Tezaroyal_1-1692212410294.png                            Tezaroyal_2-1692212429750.png

Bookings Logic =
VAR __mindate = MIN('Calendar'[Date])
VAR __maxdate = MAX('Calendar'[Date])

 

var a = sumX('report vwRevenueDashboardReport_BookingCard',IF('report vwRevenueDashboardReport_BookingCard'[Createddate]<__mindate&&'report vwRevenueDashboardReport_BookingCard'[Canceldate]>=__mindate&&'report vwRevenueDashboardReport_BookingCard'[Canceldate]<=__maxdate,-1,
IF(('report vwRevenueDashboardReport_BookingCard'[Canceldate]<__mindate&&'report vwRevenueDashboardReport_BookingCard'[Createddate]<__mindate)||('report vwRevenueDashboardReport_BookingCard'[Createddate]<__mindate&&'report vwRevenueDashboardReport_BookingCard'[Canceldate]>__maxdate)||('report vwRevenueDashboardReport_BookingCard'[Canceldate]>__maxdate&&'report vwRevenueDashboardReport_BookingCard'[Createddate]>__maxdate)||('report vwRevenueDashboardReport_BookingCard'[Createddate]>__maxdate&&'report vwRevenueDashboardReport_BookingCard'[Canceldate]=BLANK()),BLANK(),
if(('report vwRevenueDashboardReport_BookingCard'[Createddate]>=__mindate&&'report vwRevenueDashboardReport_BookingCard'[Canceldate]>__maxdate)||('report vwRevenueDashboardReport_BookingCard'[Createddate]>=__mindate&&'report vwRevenueDashboardReport_BookingCard'[Canceldate]=BLANK()),1,
if('report vwRevenueDashboardReport_BookingCard'[Createddate]>=__mindate&&'report vwRevenueDashboardReport_BookingCard'[Canceldate]<=__maxdate,0,BLANK())))))
return a
   

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Tezaroyal ,

 

I suggest you to try code as below.

Bookings Logic =
VAR _ADD =
    ADDCOLUMNS (
        'report vwRevenueDashboardReport_BookingCard',
        "Bookings Logic1",
            VAR __mindate =
                MIN ( 'Calendar'[Date] )
            VAR __maxdate =
                MAX ( 'Calendar'[Date] )
            VAR a =
                SUMX (
                    'report vwRevenueDashboardReport_BookingCard',
                    IF (
                        'report vwRevenueDashboardReport_BookingCard'[Createddate] < __mindate
                            && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] >= __mindate
                            && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] <= __maxdate,
                        -1,
                        IF (
                            ( 'report vwRevenueDashboardReport_BookingCard'[Canceldate] < __mindate
                                && 'report vwRevenueDashboardReport_BookingCard'[Createddate] < __mindate )
                                || ( 'report vwRevenueDashboardReport_BookingCard'[Createddate] < __mindate
                                && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] > __maxdate )
                                || ( 'report vwRevenueDashboardReport_BookingCard'[Canceldate] > __maxdate
                                && 'report vwRevenueDashboardReport_BookingCard'[Createddate] > __maxdate )
                                || (
                                    'report vwRevenueDashboardReport_BookingCard'[Createddate] > __maxdate
                                        && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] = BLANK ()
                                ),
                            BLANK (),
                            IF (
                                ( 'report vwRevenueDashboardReport_BookingCard'[Createddate] >= __mindate
                                    && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] > __maxdate )
                                    || (
                                        'report vwRevenueDashboardReport_BookingCard'[Createddate] >= __mindate
                                            && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] = BLANK ()
                                    ),
                                1,
                                IF (
                                    'report vwRevenueDashboardReport_BookingCard'[Createddate] >= __mindate
                                        && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] <= __maxdate,
                                    0,
                                    BLANK ()
                                )
                            )
                        )
                    )
                )
            RETURN
                a
    )
VAR _ADD2 =
    ADDCOLUMNS (
        _ADD,
        "Bookings Logic2",
            VAR _LIST =
                SUMMARIZE (
                    FILTER ( _ADD, [RevenueNumber] = EARLIER ( [RevenueNumber] ) ),
                    [Bookings Logic1]
                )
            RETURN
                IF ( 0 IN _LIST, 0, [Bookings Logic1] )
    )
RETURN
    SUMX ( _ADD2, [Bookings Logic2] )

 

Best Regards,
Rico 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

2 REPLIES 2
Anonymous
Not applicable

Hi @Tezaroyal ,

 

I suggest you to try code as below.

Bookings Logic =
VAR _ADD =
    ADDCOLUMNS (
        'report vwRevenueDashboardReport_BookingCard',
        "Bookings Logic1",
            VAR __mindate =
                MIN ( 'Calendar'[Date] )
            VAR __maxdate =
                MAX ( 'Calendar'[Date] )
            VAR a =
                SUMX (
                    'report vwRevenueDashboardReport_BookingCard',
                    IF (
                        'report vwRevenueDashboardReport_BookingCard'[Createddate] < __mindate
                            && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] >= __mindate
                            && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] <= __maxdate,
                        -1,
                        IF (
                            ( 'report vwRevenueDashboardReport_BookingCard'[Canceldate] < __mindate
                                && 'report vwRevenueDashboardReport_BookingCard'[Createddate] < __mindate )
                                || ( 'report vwRevenueDashboardReport_BookingCard'[Createddate] < __mindate
                                && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] > __maxdate )
                                || ( 'report vwRevenueDashboardReport_BookingCard'[Canceldate] > __maxdate
                                && 'report vwRevenueDashboardReport_BookingCard'[Createddate] > __maxdate )
                                || (
                                    'report vwRevenueDashboardReport_BookingCard'[Createddate] > __maxdate
                                        && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] = BLANK ()
                                ),
                            BLANK (),
                            IF (
                                ( 'report vwRevenueDashboardReport_BookingCard'[Createddate] >= __mindate
                                    && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] > __maxdate )
                                    || (
                                        'report vwRevenueDashboardReport_BookingCard'[Createddate] >= __mindate
                                            && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] = BLANK ()
                                    ),
                                1,
                                IF (
                                    'report vwRevenueDashboardReport_BookingCard'[Createddate] >= __mindate
                                        && 'report vwRevenueDashboardReport_BookingCard'[Canceldate] <= __maxdate,
                                    0,
                                    BLANK ()
                                )
                            )
                        )
                    )
                )
            RETURN
                a
    )
VAR _ADD2 =
    ADDCOLUMNS (
        _ADD,
        "Bookings Logic2",
            VAR _LIST =
                SUMMARIZE (
                    FILTER ( _ADD, [RevenueNumber] = EARLIER ( [RevenueNumber] ) ),
                    [Bookings Logic1]
                )
            RETURN
                IF ( 0 IN _LIST, 0, [Bookings Logic1] )
    )
RETURN
    SUMX ( _ADD2, [Bookings Logic2] )

 

Best Regards,
Rico Zhou

 

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

 

amitchandak
Super User
Super User

@Tezaroyal , CHeck if formula for Current Employee in blog can help

 

Power BI: HR Analytics - Employees as on Date : https://youtu.be/e6Y-l_JtCq4
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors