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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
GuestUser
Helper V
Helper V

DAX Query Help!

Hi,

 

I have a report  in below format

 

Month Forecast Quantity
Jan             100
Feb               200

Now I have 3 tables, Fact-Forecast and Dim-Item and Dim-Date

 

ForecastQuantity Measre = sum(Fact-Forecast.Forecast)

The expected value is not coming since i need to put the below filter condition(subquery)

 

Can you pls help on how to write forecast quantity measure in DAX?

 

below is the sql query which i need to write in DAX

 

select sum (f.forecast)
from
fact-forecast f,
dim-item d
where
f.item_id = d.id
and i.item_description in
(select distinct f.article_desc
from
fact-forecast f
);

10 REPLIES 10
mwegener
Most Valuable Professional
Most Valuable Professional

Hi @GuestUser ,

 

try this.

 

Forecast Quantity = SUMX(FILTER('Fact-Forecast','Fact-Forecast'[article_desc] = RELATED('Dim-Item'[item_description])), 'Fact-Forecast'[forecast])

 

 PBIX

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Thanks @mwegener 

I guess i was not clear before..

 

But the value isn't matching . Actually when i applied the DAX formula provided , the data is equivalent to below sql query (

filter of month in subquery)

 

select sum (f.forecast)
from
fact-forecast f,
dim-item d,

dim-date date
where
f.item_id = d.id

and f.date_wid = date.id

and date.month = 'April-2020'
and i.item_description in
(select distinct f.article_desc
from
fact-forecast f

where date_wid = '0420'
);

 

 

But i need DAX expression for below sql query

Should not take the month filter in the subquery. 

Ideally the data in the table is such a way that for same item_wid - item description is different in dimension and fact table

 

Can you pls suggest?

select sum (f.forecast)
from
fact-forecast f,
dim-item d,

dim-date date
where
f.item_id = d.id

and f.date_wid = date.id

and date.month = 'April-2020'
and i.item_description in
(select distinct f.article_desc
from
fact-forecast f);

mwegener
Most Valuable Professional
Most Valuable Professional

Hi @GuestUser ,

 

which table does the table alias i belong to?

 

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Hi @mwegener

 

Table alias I belong to item d

Pls find below proper query:

 

select sum (f.forecast)
from
fact-forecast f,
dim-item d,

dim-date date
where
f.item_id = d.id

and f.date_wid = date.id

and date.month = 'April-2020'
and d.item_description in
(select distinct f.article_desc
from
fact-forecast f);

mwegener
Most Valuable Professional
Most Valuable Professional

Hi @GuestUser 

 

check this.

 

Forecast Quantity = CALCULATE(SUM('Fact-Forecast'[forecast]),FILTER('Dim-Item', 'Dim-Item'[item_description] IN ALL('Fact-Forecast'[article_desc])))

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Thanks @mwegener 

 

But since I am using Connect Live-- this IN operator is giving syntax error

 

Is there any other way of writing this DAX Query?

mwegener
Most Valuable Professional
Most Valuable Professional

Hi @GuestUser ,

 

Which SSAS version did you use?

Forecast Quantity = CALCULATE(SUM('Fact-Forecast'[forecast]), FILTER('Dim-Item', CONTAINSROW(ALL('Fact-Forecast'[article_desc]), 'Dim-Item'[item_description])))

 

https://dax.guide/containsrow/

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Hi @mwegener 

 

We are using SSAS 2016

 

contains function is present but containsrow function is not there.:(

 

Any other option?

vivran22
Community Champion
Community Champion

Hello @GuestUser 

 

Can you share some sample data along with the expected output?

 

This would help in providing appropriate solution.

 

Cheers!
Vivek

Blog: vivran.in/my-blog

Connect on LinkedIn
Follow on Twitter

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.