Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Convert Dax Calculated Column to M

Hello all,

 

I am having some troube converting a DAX calculated column to M.

It would be nice to have it for a matter of having it working in a better way (to do later appends, etc.).

 

The DAX calculated column is this:

 

Value = 
VAR __WorkingDaysRow =
    CALCULATE (
        //The workday column is 1 or 0, according if it is a workday or not
        SUM ( 'Date'[Workday] ),
        DATESBETWEEN (
            'Date'[Date],
            MAX (
                //the 'Demand - Facts'[Month] is always the first day of the month
                'Demand - Facts'[Month],
                'Demand - Facts'[From]
            ),
            MIN (
                NEXTMONTH ( 'Demand - Facts'[Month] ) - 1,
                'Demand - Facts'[To]
            )
        )
    )
VAR __WorkingDaysMonth =
    CALCULATE (
        SUM ( 'Date'[Workday] ),
        DATESBETWEEN (
            'Date'[Date],
            'Demand - Facts'[Month],
            NEXTMONTH ( 'Demand - Facts'[Month] ) - 1
        )
    )
RETURN
    DIVIDE ( __WorkingDaysRow, __WorkingDaysMonth, 0 )*'Demand - Facts'[Value per Demand]
//Demand - Facts'[Value per Demand] is the FTE for each row/activity

 

Basically, I have some activites with a "From" and "To" date. I calculate for each month the number of working days and then calculate the FTEs per each month accordingly to the FTEs for the whole activity.

 

Now, I wanted to create this into M.

I already created a "Working days" Table in Power Query, with the correspondence of 0/1 for each working day.

 

So, basically, I wanted a formula in M that would:

  • Calculate the working days according to the month we are analysing (taking into account the start/end date of the month or start/end dates of activity - depending on the month in analysis)
  • Calculate a simple ratio, by dividing them
  • Multiply by the value of FTEs per activity, giving the monthly value

 

Thanks for your help,

Pedro

1 Reply

  • Doesn't sound like a calculated column or M code is helpful here.  What you can do is include a column in your calendar table that has working days per month, but that is something you should define outside of Power BI.