cancel
Showing results for
Did you mean:

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

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
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.

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.

3 REPLIES 3
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.

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

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

Announcements

#### Power BI Monthly Update - November 2023

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

#### Fabric Community News unified experience

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

#### 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