Forum Discussion

beatrizalbuqu's avatar
beatrizalbuqu
Frequent Visitor
3 years ago
Solved

Error Expression.Error: We cannot apply operator - to types Function and Function.

Hi, mates!   It's my first message here. I'm still learning the M language so please bear with me. I don't know how to fix the code below.   The main idea is to calculate working days in November...
  • m_dekorte's avatar
    m_dekorte
    3 years ago

    Thanks for clearing that up beatrizalbuqu 

     

    That means you can't refer to [FY START] or any other field (read: column name) outside a table row context. As illustrated below you have to refer to those inside Table.AddColumn's columnGenerator argument.  

    let
        startdate = #date(2022,11,01),
        enddate = #date(2022,11,30),
        // your missing steps here
        final = Table.AddColumn( Custom1, "November hours", each
             Duration.Days(
                (if [FY START] <= startdate then startdate else [FY START]) -
                (if [FY END DATE] <= enddate  then [FY END DATE] else enddate)
            ) +1, type number
        )
    in
        final

     

    I hope this is helpful