cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

Power query - Creating a Function

Hey all,

 

I'm traying to create a function in a new query.

Could you please let me know what is wrong ?

I'm getting the following error : "Token Literal expected."

 

 

= (DateValue as date, MonthEnding as number) =>
let
    CheckYear = Date.Year ( DateValue ) > Date.Year ( DateTime.LocalNow() ),
    CheckMonth = Date.Year ( DateValue ) = Date.Year ( DateTime.LocalNow() ) and Date.Month ( DateValue ) > MonthEnding,

    FiscalYear2 = 
        if 
            CheckYear
        then
            "NY"
        else
            if 
                CheckMonth
            then
                "NY"
            else
                "CY"

in 
    FiscalYear2

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Power query - Creating a Function

HI @lucianosabella,

You can try to use following M query code if it suitable for your requirement:

(DateValue as date, MonthEnding as number) as text=>
    let
        CheckYear = Date.Year ( DateValue ) > Date.Year ( DateTime.LocalNow() ),
        CheckMonth = Date.Year ( DateValue ) = Date.Year ( DateTime.LocalNow() ) and Date.Month ( DateValue ) > MonthEnding,
        FiscalYear2 = 
            if 
                CheckYear
            then
                "NY"
            else if 
                    CheckMonth
                then
                    "NY"
                else
                    "CY"

    in 
        FiscalYear2

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
Highlighted
Community Support
Community Support

Re: Power query - Creating a Function

HI @lucianosabella,

You can try to use following M query code if it suitable for your requirement:

(DateValue as date, MonthEnding as number) as text=>
    let
        CheckYear = Date.Year ( DateValue ) > Date.Year ( DateTime.LocalNow() ),
        CheckMonth = Date.Year ( DateValue ) = Date.Year ( DateTime.LocalNow() ) and Date.Month ( DateValue ) > MonthEnding,
        FiscalYear2 = 
            if 
                CheckYear
            then
                "NY"
            else if 
                    CheckMonth
                then
                    "NY"
                else
                    "CY"

    in 
        FiscalYear2

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

Highlighted
New Member

Re: Power query - Creating a Function

Thanks so much!

Helpful resources

Announcements

August Community Highlights

Check out a full recap of the month!

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

Top Solution Authors