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

Sum by month

Hi everyone,

I have a problem to do something very simple on excel but so hard on power BI

I have a project table with my project Name, starting date, excepted ending date and ending date

So I'd like to nake some calculation with these data so this is an example, I'd like by month all the project which start at month M and which finished at M+1

So to do that, I built a second table: Month in it I put the month for I want to make the count

 

With these screenshots, I think everything will be easier for you

So I have two table one project and one month

 

MonthTable.pngProjectTable.png

 

I built a relationship between the both table:

RelationShip.png

After that, I'd like to count with a measure(or a column) my project which start the same month than the month in my date table and which are finished one month later so I thought to do that with:

Measure = CALCULATE(COUNT(Project[Starting Date]);('Date'[Month]= 'Project'[starting Date]);((DATEADD('Date'[Month];1;MONTH)='Project'[ending Date])))

I aslo tried it with a new column:

Column = CALCULATE(COUNT(Project[Starting Date]);('Date'[Month]= 'Project'[starting Date]);((DATEADD('Date'[Month];1;MONTH)='Project'[ending Date])))

 

But nothing worked

 

Any idea of what I could do?

6 REPLIES 6
v-jiascu-msft
Employee
Employee

Hi @domiowa,

 

Could you please mark the proper answer as solution?

 

Best Regards!
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-jiascu-msft
Employee
Employee

Hi @domiowa,

 

Try out these two measues please. You also can check it out in this file.

Measure 1 =
SUMX (
    SUMMARIZE (
        'Project',
        'Project'[Project],
        Project[Starting Date],
        Project[EndingDate],
        "Months", DATEDIFF ( Project[Starting Date], Project[EndingDate], MONTH )
    ),
    IF ( [Months] = 1, 1, BLANK () )
)
Measure 2 =
CALCULATE (
    COUNTROWS ( 'Project' ),
    FILTER (
        'Project',
        MONTH ( 'Project'[EndingDate] ) - MONTH ( Project[Starting Date] )
            = 1
    )
)

Sum_by_month

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
jdobrzen
Advocate II
Advocate II

If you're trying to figure out the difference between Starting Date and Ending Date where the difference is 1 month, could you solve that with a calculated column and then a mesure to count the instances?

 

+1M Indicator Column = IF(DATEDIFF(Starting Date, EndingDate, month) = 1, TRUE(), FALSE())

 

Count +1M Finish = COUNTROWS(FILTER(myTable, +1M Indicator Column = TRUE()))

Thanks for your answer but the problem is I'll have other calculation to do so the difference won't be all the time one month

I'll take one more shot 🙂

 

If you need it to be dynamic so it has to be a measure, then maybe you can leverage a parameter table.  It looks like you might already be trying to do that with your seperate Month table.

 

https://www.daxpatterns.com/parameter-table/

 

= IF (HASONEVALUE ( myParmTable[myParm] ),

                COUNTROWS(FILTER(myTable, DATEDIFF(Starting Date, EndingDate, month) = VALUES(myParmTable[myParm])))

                ,0

)

I tried it but it doesn't work
Weird how things which are so easy on excel are so hard on BI

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.