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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.