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
Anonymous
Not applicable

How to Sum up DAX with "DATESINBETWEEN"

Hi Power BI, 

I created a New Measure being "

Total Ans. Chats (Prev Mth) = CALCULATE(SUM('2 Chatsdata'[Chats/Visitors]),'2 Chatsdata'[Chats (type)]="chats",DATESBETWEEN('2 Chatsdata'[Date (MMYY)],[Date2 (start)],[Date2 (end)]))

The issue I have is when I slect more than 1 Month, it is not totalling (instead it select the Latest Month value)

 

Date2 (start) = MAX('2 Chatsdata'[Date (MMYY)]) - 45

Date2 (end) = MAX('2 Chatsdata'[Date (MMYY)]) - 15

 

 

How do i get this to total ?

Total Prev mth.jpg

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Per my understanding, the result of a measure will be affected by context, that is why you cannot get the total value aftering using DatesBetween to filter.

 

In this scenario, we can use column to get the desired result.

 

In your source table '2 Chatsdata', create below calculated columns:

Date2 (start) col =
DATEADD ( '2 Chatsdata'[Date (MMYY)], -1, MONTH )

Sum current month =
CALCULATE (
    SUM ( '2 Chatsdata'[Chats/Visitors] ),
    ALLEXCEPT (
        '2 Chatsdata',
        '2 Chatsdata'[Chats (type)],
        '2 Chatsdata'[Date (MMYY)]
    )
)

Rank =
IF (
    [Date2 (start) col] <> BLANK (),
    RANKX (
        FILTER (
            '2 Chatsdata',
            '2 Chatsdata'[Chats (type)] = EARLIER ( '2 Chatsdata'[Chats (type)] )
        ),
        '2 Chatsdata'[Date (MMYY)],
        ,
        ASC,
        DENSE
    ),
    BLANK ()
)

Sum previous month =
IF (
    '2 Chatsdata'[Chats (type)] = "chats",
    LOOKUPVALUE (
        '2 Chatsdata'[Sum current month],
        '2 Chatsdata'[Chats (type)], '2 Chatsdata'[Chats (type)],
        '2 Chatsdata'[Rank], '2 Chatsdata'[Rank] - 1
    ),
    BLANK ()
)

3.PNG

4.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

thank you for attempting this.. I can see it working on your PBI.. For me the DAX is well beyond my ability to comprehend... I also cannot get it to work on my PBI.. Lets close this.

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.