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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply

Make a Column using DAX that fetches value for only first date of month

Hi everyone, 

Sorry if the title is not very clear, so I'll try to detail the ask/request in detail here. 
I have a dataset/table "HelloWorld" that looks like below

 

DateTypeValue
2022-04-01A100
2022-04-01A50
2022-04-01B30
2022-04-01C10

2022-04-02

B20
2022-04-02C10
2022-05-01A200
2022-05-01A100
2022-05-01B50
2022-05-01C10

 

I want a calculated column which will be fed to a card, and a Date filter/slicer drop-down visual will be connected to that. I want the calculated column to show -
For any selected date of the month, the output value should be SUM of all Value for 1st of that month where Type = A.

So if the Date is selected as 2022-04-01, the Value shown on the card should be 150 (100 + 50 for two Type = A entries of 2022-04-01). 
If the date is 2022-04-01 (or any date in 2022-04) the value should still be 150.

 

If the Date selected is now changed 2022-05-01, the value shown on the card should be 300 (200 + 100 for two Type = A entries of 2022-05-01), and same for any date selected in 2022-05. And so on. 

I tried the following piece of code, which gave me erroneous result - 

VAR startMonth = STARTOFMONTH(HelloWorld[Date])
RETURN CALCULATE(SUM(HelloWorld[Value]), FILTER (HelloWorld,HelloWorld[Date] == startMonth),FILTER (HelloWorld, HelloWorld[Type] == "A"))

Any help will be hugely appreciated. Thanks in advance.
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @tintinsherlock ;

You could create a measure.

First Value = 
VAR _startMonth = STARTOFMONTH('Table'[Date])
RETURN CALCULATE(SUM([Value]),FILTER(ALL('Table'),[Date]=_startMonth&&[Type]="A"))

The final shown :

vyalanwumsft_0-1652422473641.pngvyalanwumsft_1-1652422479939.png

vyalanwumsft_2-1652422485590.png


Best Regards,
Community Support Team _ Yalan Wu
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

5 REPLIES 5
v-yalanwu-msft
Community Support
Community Support

Hi, @tintinsherlock ;

You could create a measure.

First Value = 
VAR _startMonth = STARTOFMONTH('Table'[Date])
RETURN CALCULATE(SUM([Value]),FILTER(ALL('Table'),[Date]=_startMonth&&[Type]="A"))

The final shown :

vyalanwumsft_0-1652422473641.pngvyalanwumsft_1-1652422479939.png

vyalanwumsft_2-1652422485590.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Exactly what I needed. Thank you so much! 

Whitewater100
Solution Sage
Solution Sage

Hi:

You could add a calculated column to Table.

First Month Value =
CALCULATE(SUM('Table'[Value]),
'Table'[Type] = EARLIER('Table'[Type]),ALLEXCEPT('Table','Table'[Date]))
If you set date slicer to first of month the answer should be ok. I hope this helps!
Whitewater100_0-1652185574013.png

 

Hey @Whitewater100 That's the thing. I want the value of the all the days of the month to be the same as the first of the month. 
So 150 should be the value for all days of 2022-04 and 300 for 2022-05 and so on. 
So even if someone selects the other day on the slicer, they see this same value. 
(Context - this value represents a monthly count so no it should show this value no matter what date) 
Is there any other solution you can suggest?

Hi:

Can you check this out? Please see page 2. (I combine replies sometimes)

https://drive.google.com/file/d/1ZAjWFdUWn39_GSDDYaxck8oLgzPNd1-_/view?usp=sharing 

Whitewater100_0-1652188820802.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors