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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
cheid_4838
Helper IV
Helper IV

SQL SSRS Declare Statement in Power BI

I have a query that has @year, @month, @budget that I need to figure out how to get to work in Power BI. The query is referencing tables from Microsoft Dynamics Great Plains. Does anyone know how to get these to work in Power BI?  I know how to get them to work in SSRS, but not in Power BI. Your help is greatly appreciated.

 

 

create procedure gprv_actual_vs_budget
@year int, @month int, @budget varchar(15)
as

set nocount on

select
rtrim(an.ACTNUMST) Account,
rtrim(m.ACTDESCR) [Account Description],
coalesce(a.Monthly,ah.Monthly,0) [Monthly Actual],
coalesce(b.Monthly,0) [Monthly Budget],
coalesce(a.Monthly,ah.Monthly,0)
- coalesce(b.Monthly,0) [Monthly Variance],
coalesce(a.YTD,ah.YTD,0) [YTD Actual],
coalesce(b.YTD,0) [YTD Budget],
coalesce(a.YTD,ah.YTD,0)
- coalesce(b.YTD,0) [YTD Variance]
from GL00105 an -- account numbers

left outer join --actuals from open year
(select a.ACTNUMST,
sum(case when g.PERIODID = @month
then g.DEBITAMT - g.CRDTAMNT
else 0
end) Monthly,
sum(case when g.PERIODID <= @month
then g.DEBITAMT - g.CRDTAMNT
else 0
end) YTD
from GL11110 g
inner join GL00105 a
on g.ACTINDX = a.ACTINDX
where g.YEAR1 = @year and g.PERIODID <= @month
group by a.ACTNUMST) a --actuals open year
on an.ACTNUMST = a.ACTNUMST

left outer join --actuals from historical year
(select a.ACTNUMST,
sum(case when g.PERIODID = @month
then g.DEBITAMT - g.CRDTAMNT
else 0
end) Monthly,
sum(case when g.PERIODID <= @month
then g.DEBITAMT - g.CRDTAMNT
else 0
end) YTD
from GL11111 g
inner join GL00105 a
on g.ACTINDX = a.ACTINDX
where g.YEAR1 = @year and g.PERIODID <= @month
group by a.ACTNUMST) ah --actuals historical year
on an.ACTNUMST = ah.ACTNUMST

left outer join --budgets
(select a.ACTNUMST,
sum(case when b.PERIODID = @month
then b.BUDGETAMT
else 0
end) Monthly,
sum(case when b.PERIODID <= @month
then b.BUDGETAMT
else 0
end) YTD
from GL00201 b
inner join GL00105 a
on b.ACTINDX = a.ACTINDX
where b.BUDGETID = @budget and b.YEAR1 = @year
group by a.ACTNUMST) b --budgets
on an.ACTNUMST = b.ACTNUMST

left outer join GL00100 m --account master
on an.ACTINDX = m.ACTINDX

--only show rows that are not all zeros,
--if you want to see all accounts,
--remove the where clause below
where a.Monthly <> 0
or a.YTD <> 0
or b.Monthly <> 0
or b.YTD <> 0
or ah.Monthly <> 0
or ah.YTD <> 0

order by an.ACTNUMST

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@cheid_4838 have you looked at this post: Solved: Passing PowerBI Parameter To A Stored Procedure - Microsoft Fabric Community



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi, @cheid_4838 

Thanks for parry2k's reply. Could you please share the table containing all the required information without sensitive data, the desired output and the logic on how to achieve the desired result. We are more familiar with DAX than SQL, if you can give the above required information it will help us to solve your problem faster, thanks for your understanding.

 

Best Regards,
Yang

Community Support Team

parry2k
Super User
Super User

@cheid_4838 have you looked at this post: Solved: Passing PowerBI Parameter To A Stored Procedure - Microsoft Fabric Community



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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