cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Anonymous
Not applicable

Convert DAX to M

Hello Everyone!

Coluld you please convert Dax to M for me?

The formula calcalated the quatity of days in the monts and quatity of passed days in the current months minus 1.

 

Quantity of days =

if('Accounting Date'[Year] = YEAR(TODAY()) && 'Accounting Date'[Month] = MONTH(TODAY()),

DAY (EOMONTH ('Accounting Date'[Accounting Date], 0 ) ) -

DATEDIFF (NOW (), EOMONTH (NOW (), 0 ), DAY )-1,

DAY (EOMONTH ('Accounting Date'[Accounting Date].[Date], 0 )))

 

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

Hi @Anonymous ,

 

Here I suggest you to create a Custom Column in Power Query Editor by this code.

let 
_Today =DateTime.Date(DateTime.LocalNow()),
_Endoftoday = Date.EndOfMonth(_Today),
_EndofAccountingDate = Date.EndOfMonth([Accounting Date])
in
if 
[Year] = Date.Year(_Today) 
and
[Month] = Date.Month(_Today) 
then 
Date.Day(_EndofAccountingDate)
-
Duration.Days(_Endoftoday-_Today)-1
else 
Date.Day(_EndofAccountingDate)

Result is as below. 

RicoZhou_0-1673503829663.png

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous ,

 

Here I suggest you to create a Custom Column in Power Query Editor by this code.

let 
_Today =DateTime.Date(DateTime.LocalNow()),
_Endoftoday = Date.EndOfMonth(_Today),
_EndofAccountingDate = Date.EndOfMonth([Accounting Date])
in
if 
[Year] = Date.Year(_Today) 
and
[Month] = Date.Month(_Today) 
then 
Date.Day(_EndofAccountingDate)
-
Duration.Days(_Endoftoday-_Today)-1
else 
Date.Day(_EndofAccountingDate)

Result is as below. 

RicoZhou_0-1673503829663.png

 

Best Regards,
Rico Zhou

 

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, Rico

amitchandak
Super User
Super User

@Anonymous , Try like

 

if Date.EndOfMonth(DateTime.Date(DateTime.LocalNow()))= Date.EndOfMonth('Accounting Date'[Accounting Date])
then Duration.Days(DateTime.Date(DateTime.LocalNow()) - Date.StartOfMonth(DateTime.Date(DateTime.LocalNow())) ) -1
else Date.Day(Date.EndOfMonth('Accounting Date'[Accounting Date]))

 

As I have used Start of Month, You might not need -1

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors