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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
TANA
Advocate II
Advocate II

How to reference a query (table)

Hi,

I have the following query which is also a table. I am thinking to use CALCULATE as a measure in Power BI report, but I don't know how to reference different row in the query by situation?

 

TANA_1-1740013549871.png



For example, when I create a measure called "2025 control budget", I would like combine two set of data, Actual cost data will come from a query which any cost before and include 2024 Dec data, then forecast cost data will come another query which will include cost info from Jan 2025 and onward. I plan to create four measures as listed under Name column.

Can you please provide me some suggestions? Thanks,

5 REPLIES 5
rajendraongole1
Super User
Super User

Hi @TANA  - you can structure your measure for "2025 Control Budget"

 

2025 Control Budget =
VAR SelectedForecast = SELECTEDVALUE( 'YourTable'[Forecast] )
RETURN
CALCULATE(
SUM( 'ActualCostTable'[Cost] ),
'ActualCostTable'[Date] <= DATE(2024,12,31)
) +
CALCULATE(
SUM( 'ForecastCostTable'[Cost] ),
'ForecastCostTable'[Date] >= DATE(2025,1,1)
)

 

replace with your table name, or the other measures (Prev Month -1 Forecast HCC, Prev Month Forecast HCC, Working Forecast), you can create similar measures but adjust the date filters accordingly.

 

Hope this helps.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi, rajendraongole1:

 

Thanks for your help. Appreciated!

I am wondering if the highlighted yellow dates can be directly referenced to the query above from different rows, which I shared earlier based on which measure I set up. 

 

TANA_0-1740081832294.png

 

HI @TANA,

You can put this part into variable and use if statement or switch function to handle and return different results based on calculation groups.

Using calculation groups to selectively replace measures in DAX expressions - SQLBI

Create calculation groups in Power BI - Power BI | Microsoft Learn

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi, @v-shex-msft:

Thanks for your reply and help. Appreciated! Would you mind helping me further? 

My situation is like this:

I have the following three queries for which, one side has the actual up to date cost data, and the other has forecast and budget cost data. Both data sets has similar structure.

TANA_1-1740116969120.png

Both Actual and Budget forecast queries have the following similar content.

TANA_2-1740117010125.png

Then I have the third query which was shared earlier. 

TANA_3-1740117065397.png

Eventually, I would like to have a report which has a field parameter of 2025 control budget, working forecast, prev month's forecast or prev prev month's forecast. And the report will be a matrix with funding code as row header, and time as column header.

I was thinking about using CALCULATE as discussed earlier. would you mind giving me more directions on how? or is there any other methods to achieve the same result? please let me know. Thanks,

 

 

HI @TANA,

So you mean you just want to summary records from two table based on current column values?
If that's the case, you can add calculated columns to use current Name and date to look up correspond table records.

Actual =
CALCULATE (
    SUM ( ActualTable[amount] ),
    FILTER (
        ActualTable,
        [version_name] = EARLIER ( SummaryTable[name] )
            && [month_number] = EARLIER ( SummaryTable[actual] )
    )
)

Forecast =
CALCULATE (
    SUM ( Forecase[amount] ),
    FILTER (
        ActualTable,
        [version_name] = EARLIER ( SummaryTable[name] )
            && [month_number] = EARLIER ( SummaryTable[forecast] )
    )
)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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