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
Femi10
Frequent Visitor

DAX Calculation for events that happens in the same month as another event

Good evening all,

 

Below is the structure of my data. I want to run a report that counts the number of invoices that were invoiced and completed in the same calendar month.

 

Please how do I go about it?

 

Femi10_0-1637621280812.png

 

Thank you 

 

@smpa01

@Greg_Deckler
@AlexisOlson

@amitchandak

 

 

 

7 REPLIES 7
smpa01
Super User
Super User

@Femi10  I think the following will give you what you need and you would not need a Calendar Table at all.

Measure = 
COUNTROWS (
    FILTER (
        tbl,
        YEAR ( tbl[invoice Date] ) = YEAR ( tbl[Completed Date] )
            && MONTH ( tbl[invoice Date] ) = MONTH ( tbl[Completed Date] )
    )
)

 

smpa01_0-1637780403772.png

 

  

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@Femi10  did you have a chance to look into the solution I provided?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Femi10
Frequent Visitor

Hi 

Thank you so much, I just checked it a few minutes ago. It still didn't provide the correct answer.  

However, I found another way to go about it which counted the monthly columns correctly,  the problem with it is that it's giving me a wrong column total.

 

CALCULATE([DistinctJobCount],
DATESBETWEEN('Payment Count'[Completed Date], STARTOFMONTH('Date'[Date]), ENDOFMONTH('Date'[Date].[Date])))

 

Here is a screenshot of my visual. "Me" is the DAX I wrote above(with the wrong total) and SMPA is the Dax you sent to me.
Mine is the correct one

Femi10_1-1637882422969.png

 

 

Could you please show me how I would approach it if I wanted to do a distinct count rather than a normal count?

 

@Femi10  my solution was based on the data that you provided and you can see that it works.

 

If the sample data is not represntative of the issue and if you hvae not provided other details, please post the pbix reprentative of your issue and someone will look into it.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Femi10
Frequent Visitor

@smpa01 Thank so much for the help. It is well appreciated

smpa01
Super User
Super User

@Femi10  one way of achieving, with Calendar Table, pbix is attached

Measure5 = 
COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            ADDCOLUMNS ( tbl, "invDetails", RELATED ( 'Calendar'[Year-Month] ) ),
            "completedDetails",
                CALCULATE (
                    CALCULATE (
                        MAXX ( 'Calendar', 'Calendar'[Year-Month] ),
                        TREATAS ( VALUES ( tbl[Completed Date] ), 'Calendar'[Date] )
                    )
                )
        ),
        [invDetails] = [completedDetails]
    )
)

 

smpa01_0-1637636908566.png

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Femi10
Frequent Visitor

Thank you

It didn't quite work, I suspect this might be connected to the introduction of the Calendar Table.

Can you please give a brief explanation of your DAX, that could help me find my way around it.

 

What do I change if I want to count distinct invoice numbers? (some invoice numbers there appeared more than once)

Many thanks

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.

Top Solution Authors