Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Dynamic parameters for week/year in SAP BW

Hello,

I have read about a solution,you find it below, but I still not manage to fix it.

If I change in the code below 1 into 10 then it will return week 10 (old example).

The soluation was that you can add as much weeks as you want but how ?

I for example want to add 52 weeks.

 

Humberto1959_2-1652280820341.png

MyFunction is a written code that assures that the weeks has two digits

 

let
    ThisWeek = MyFunction(Date.From(DateTime.FixedLocalNow())), 
    NextWeek = MyFunction(Date.From(Date.AddWeeks(DateTime.FixedLocalNow(),1)))
in
    {ThisWeek,NextWeek}

 

Humberto1959_0-1652280736672.png

 

8 REPLIES 8
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

In your code, DateTime.FixedLocalNow() returns a datetime value set to the current date and time. Date.From() extracts the date value from the value inside. Date.AddWeeks returns the datetime result from adding numberOfWeeks weeks to the datetime value inside. When you insert 10, it returns the datetime which is 10 weeks later after the current datetime. This is correct. 

 

If it doesn't meet your requirement, what is the expected result you want to get?

 

Best Regards,
Community Support Team _ Jing

Anonymous
Not applicable

Hello v-jingzhang,

 

Thanxs for your reaction. I understand your explanation but what I want is not returning just one value in the Addsweek code but 52 weeks so I have the values of 52 weeks forwards.

Hi @Anonymous 

 

Sorry I misunderstood it. So here you need to generate a list for it. Try something like below. Replace "202101" and "202152" with your ThisWeek and NextWeek parameters.

List.Transform({202101..202152}, each "[0CALWEEK].["&Text.From(_)&"]")

vjingzhang_0-1652781697293.png

 

Then use this list to replace the highlighted list in below code. 

vjingzhang_1-1652781987690.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Anonymous
Not applicable

Hi v-jingzhang,

 

The code below doesn't give a syntax error, but if I close the editor this failure is popping up

Expression.Error: 1 arguments were passed to a function which expects 2.
Details:
Pattern=
Arguments=[List]

 

Humberto1959_0-1652864987039.png

 

 

 

Hi @Anonymous 

 

Try replacing the whole line in Advanced editor with below one. MyFunction is the function you mentioned in your initial post. It should convert a date to the format as "202212" which combines year and week number. 

{Cube.ApplyParameter, "[!V000005]", List.Transform({ Number.From(MyFunction(Date.From(DateTime.FixedLocalNow()))) .. Number.From(MyFunction(Date.From(Date.AddWeeks(DateTime.FixedLocalNow(),10))))}, each "[0CALWEEK].["&Text.From(_)&"]"),

 

Jing

Anonymous
Not applicable

Hello Jing

 

edited as you recommended but the message is 

 

Expression.Error: 3 arguments were passed to a function which expects 2.
Details:
Pattern=
Arguments=[List]

 

Humberto1959_0-1652953745386.png

 

Hi @Anonymous 

 

If you use only two dates on the row, just like in your original post, is it able to get data correctly? According to the error message it mentions "3 arguments were passed to a function which expects 2" but I'm not sure which function is it. 

Anonymous
Not applicable

Hello Jing,

If I use it in my original post I get the same result namely two weeks, this week and just one week in the future.

The funciton I use is :

 

let
Quelle = if
Number.RoundDown((Date.DayOfYear(dDate )-(Date.DayOfWeek(dDate , Day.Monday)+1)+10)/7)=0

then
Number.ToText(Date.Year(dDate)-1)&Number.ToText(Number.RoundDown((Date.DayOfYear(#date(Date.Year(dDate )-1,12,31))-(Date.DayOfWeek(#date(Date.Year(dDate )-1,12,31), Day.Monday)+1)+10)/7))

else if
(Number.RoundDown((Date.DayOfYear(dDate )-(Date.DayOfWeek(dDate , Day.Monday)+1)+10)/7)=53
and (Date.DayOfWeek(#date(Date.Year(dDate ),12,31), Day.Monday)+1<4))

then
Number.ToText(Date.Year(dDate)+1)&"01"

else
Number.ToText(Date.Year(dDate))&Number.ToText(Number.RoundDown((Date.DayOfYear(dDate)-(Date.DayOfWeek(dDate, Day.Monday)+1)+10)/7))
in
Quelle

 

Maybe this will help you

 

Regards,

Huib

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.