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
Gjakova
Post Patron
Post Patron

Value on the first day and last day of the month

Hi there, I need to calculate the revenue of each month. To be specific, it is not a month in general but the first day of the month (for example: September 1st, 2021).

So that would be measure A.

Measure B would be calculating the value of the last day of the month (September 30th, 2021) orthe first day of next month (October 1st, 2021).

Once I got measure A & B, I need to drop them in a matrix table which looks like this:

ProductDateMeasure ARevenue Avg. monthMeasure B
AlphaSeptember 1st, 202120.52124
AlphaOctober 1st, 202124138
AlphaNovember 1st, 2021830100

I assume I need to work with CALCULATE + the filter function, but I can't get it to work. Hope someone can push me in the right direction!

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Gjakova ,

I created some data:

vyangliumsft_0-1632201793985.png

Here are the steps you can follow:

1. Create calculated column.

Date1 = DATE(YEAR('Table'[date]),MONTH('Table'[date]),1)

And convert the format:

vyangliumsft_1-1632201793990.png

2. Create measure.

MeasureA = CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),'Table'[date]=DATE(YEAR(MAX('Table'[date])),MONTH(MAX('Table'[date])),1)&&'Table'[Product]=MAX('Table'[Product])))
MeasureB =
var _1=
CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),'Table'[date]=DATE(YEAR(MAX('Table'[date])),MONTH(MAX('Table'[date]))+1,1)&&'Table'[Product]=MAX('Table'[Product])))
return
IF(_1 = BLANK(),CALCULATE(SUM('Table'[amount]),FILTER('Table','Table'[date]=EOMONTH('Table'[date],0)&&'Table'[Product]=MAX('Table'[Product]))),_1)

3. Result:

MeasureA: for the beginning of the month

MeasureB: When there is a value at the beginning of the next month, it is the value of this month, if there is no value at the beginning of the next month, it is the value at the end of the month

vyangliumsft_2-1632201793992.png

 

Best Regards,

Liu Yang

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

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @Gjakova ,

I created some data:

vyangliumsft_0-1632201793985.png

Here are the steps you can follow:

1. Create calculated column.

Date1 = DATE(YEAR('Table'[date]),MONTH('Table'[date]),1)

And convert the format:

vyangliumsft_1-1632201793990.png

2. Create measure.

MeasureA = CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),'Table'[date]=DATE(YEAR(MAX('Table'[date])),MONTH(MAX('Table'[date])),1)&&'Table'[Product]=MAX('Table'[Product])))
MeasureB =
var _1=
CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),'Table'[date]=DATE(YEAR(MAX('Table'[date])),MONTH(MAX('Table'[date]))+1,1)&&'Table'[Product]=MAX('Table'[Product])))
return
IF(_1 = BLANK(),CALCULATE(SUM('Table'[amount]),FILTER('Table','Table'[date]=EOMONTH('Table'[date],0)&&'Table'[Product]=MAX('Table'[Product]))),_1)

3. Result:

MeasureA: for the beginning of the month

MeasureB: When there is a value at the beginning of the next month, it is the value of this month, if there is no value at the beginning of the next month, it is the value at the end of the month

vyangliumsft_2-1632201793992.png

 

Best Regards,

Liu Yang

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

edhans
Super User
Super User

@Gjakova - we really need a bit more info. For example, "Measure B would be calculating the value of the last day of the month (September 30th, 2021) orthe first day of next month (October 1st, 2021)." Which is it? the last day of current month or first of next? I can return one or the other, but not both.

You've also given us no actual data. You started with Measure A results, so no source data.

That said, this logic may help:

Measure 1 = 
var varSelectedDate = SELECTEDVALUE('Date'[Date])
VAR varDate = EOMONTH(varSelectedDate,-1) + 1
VAR Result = 
    CALCULATE(
        SUM('Table'[Measure A]),
        KEEPFILTERS('Date'[Date] = varDate)
    )
RETURN
Result

edhans_0-1631750150461.png
Using EOMONTH, I took the current date, moved back to the last day of the previous month, then added a day, so Sept 1 through Sept 30 will always go back to August 31, then add a day and arrive back at Sept 1. You can manipulate that formula. You could use EOMONTH(varSelectedDate,0) + 1. Sept 15 would return Oct 1 in that case.

You need a date table too. I have one here. Creating a Dynamic Date Table in Power Query
Lastly, here is my PBIX file, complete with a date table and the measures I used. 

But if you want a more comprehensive answer, we need more info and definitely more data. Remember, you know your data very well. We know nothing. Be very explicit with the requirements. Thanks!

How to get good help fast. Help us help you.

How To Ask A Technical Question If you Really Want An Answer

How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Hi @edhans, thank you for your reply, I tried your measure but it did not work. Here is a bit more explanation:

Basically it looks like an Opening and Closing balance. 

So perhaps the example is not that great, but the reason that I said that measure B could either be the last day of the current month or the first day of the next month, is because their value should ALWAYS be the same. Since Closing Balance of the last day of the month, is the Opening Balance on the first day of the month.

Measure A basically needs to ALWAYS give me what the value was on the first day of the CURRENT month that I am in on the table. So if my table looks like:

ProductDateMeasure AMeasure B

Samsung

September, 2020 (only first day of the month)80 (value on September 1st)100 (Opening balance on October 1st or Closing Balance on September 31 (result should be the same))
SamsungOctober, 2020 (only first day of the month)100 (value on October 1st)40 (opening value on November 1st or closing value on October 31)
SamsungNovember, 2020 (only first day of the month)40 (value on November 1st)80 (opening value on December 1st or closing balance on November 31)

 

Hope this is a bit more clear.

No, it really isn't. Maybe someone else understand where you are going. They say a picture is worth 1,000 words. For me, some tables with data is worth more than several paragraphs of explanation. You've still provided no data, just measure results you expect me to write to calculate over data I've not seen.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.