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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Conditional Block on MScript

Hi , I am trying try to do M with conditional block.  The Idea is, if the report period parameter selected is less than today then it will pull data from Sales_country1 table if it is greater than today then Sales_country2 . 

 

 

let
Source = Sql.Database("SERVERNAME", "DATABASE"),

#"sales_country1" = Source{[Schema="dbo",Item="sales_country1"]}[Data],

#"sales_country2" = Source{[Schema="dbo",Item="sales_country2"]}[Data],

#"checkperiod" = if @reportperiod <= DateTime.LocalNow()
then #"sales_country1"
else #"sales_country2"
in
#"checkperiod"

 

The output of this M is not showing the table with data. it shows a text [Table].  I think the issue with IF Then Else statement. I would like to see the table with data but not sure where i am going wrong here. 

 

Any help would be appreciated. Thanks 

5 REPLIES 5
Jimmy801
Community Champion
Community Champion

Hello @Anonymous

 

the code is perfectly fine. What is Power Query showing if you select the step #"sales_country1" or #"sales_country2"? Where is the parameter "@reportperiod " coming from?

 

BR

 

Jimmy

Anonymous
Not applicable

If i do just #"sales_country1" or #"sales_country1" then i get the table with data. 

Anonymous
Not applicable

@reportperiod will get value from parameter.  Even if I hardcode a value it is still coming up with [TABLE]. The code excutes without error but the output is not in table form. please see image below.

 

dimsandfacts_0-1604582204474.png

 

 

 

Thanks 

 

 

Hello @Anonymous 

 

you didn't answer my questions at all

What is your parameter? can you show me the previews of you two tables please

 

Jimmy

Anonymous
Not applicable

Hi Jimmy,
Thanks for the reply. Even if you take the parameter out of the query, as shown below i still get the Text as output not the table. 

 

let
Source = Sql.Database("SERVERNAME", "DATABASE"),

#"sales_country1" = Source{[Schema="dbo",Item="sales_country1"]}[Data],

#"sales_country2" = Source{[Schema="dbo",Item="sales_country2"]}[Data],

#"checkuser" =
if @SaleManager = "John.Smith"

then #"sales_country1"
else #"sales_country2"
in
#"checkperiod" 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

Top Solution Authors
Top Kudoed Authors