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

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

Reply
IvensaMDH
Frequent Visitor

Calculate filter based on multiple table variables

Hi,

 

I want to filter a calculation based on several table variables as below, however i am unable to reference the "Time" or "Sla" column of the "Data" table after filtering.

Is this possible and if so how would i go about doing it..? (There may be multiple filter on multiple columns).

Result = 
VAR A = FILTER(Data, Data[Type] = 1)
VAR B = FILTER(Data, Data[Type] = 2)
VAR C = FILTER(Data, Data[Type] = 3)
RETURN CALCULATE(COUNTROWS(A) / COUNTROWS(B) * COUNTROWS(C), A[Time] > B[Time], C[Sla] < A[Sla])

 Thanks in advance!

 

/Mathias

 

5 REPLIES 5
Anonymous
Not applicable

Hi @IvensaMDH ,

 

According to my understanding, it seems that you want  to create a new table with Ids that there are Time for Type 1 and Type 2 ,and then get the time duration.

If so ,please try:

New Table =
VAR _t =
    SUMMARIZE (
        'Table',
        'Table'[Id],
        "Type 1 Time", LOOKUPVALUE ( 'Table'[Time], 'Table'[Id], [Id], 'Table'[Type], 1 ),
        "Type 2 Time", LOOKUPVALUE ( 'Table'[Time], 'Table'[Id], [Id], 'Table'[Type], 2 )
    )
RETURN
    ADDCOLUMNS (
        FILTER ( _t, [Type 1 Time] <> BLANK () && [Type 2 Time] <> BLANK () ),
        "Time Diff(Minutes)",
            ( [Type 2 Time] - [Type 1 Time] ) * 24 * 60
    )

Output:

Eyelyn9_0-1648110913234.png

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Anonymous ,

 

Thank you! This is exactly what i was looking for and done in an elegant way.

 

We do, however, have one slight edge case;

Sometimes, an entity will produce several events of the same type, but with different time. Example:

 

IdTypeTime
1115-03-2022 10:00:00
1215-03-2022 11:00:00
2115-03-2022 10:00:00
3115-03-2022 10:00:00
3215-03-2022 12:00:00
4215-03-2022 13:00:00
1115-03-2022 17:00:00
1215-03-2022 19:30:00

 

In the above example, the entity with [Id] = 1 has produced 2 "sets" of events (a set being an event of [type] = 1 followed by an event of [type] = 2). Because of this, i have changed the query to FIRSTNONBLANKVALUE instead of LOOKUPVALUE (otherwise there may be multiple values returned).

 

I do however wonder, if it would be possible to traverse above table, and collect "sets" of events, producing the following:

 

IdType 1 TimeType 2 Time
115-03-2022 10:00:0015-03-2022 11:00:00
315-03-2022 10:00:0015-03-2022 12:00:00
115-03-2022 17:00:0015-03-2022 19:30:00

 

If you have any suggestions i'd love to hear them as it would be a great help for us!

 

Br,

 

/Mathias

Anonymous
Not applicable

Hi @IvensaMDH ,

 

Please try to use SUMMARIZE() to filter table, then you could reference the columns. For example:

Measure = 
var A= SUMMARIZE(FILTER('Data',[Type]=1),[Time],[Sla])
var B= SUMMARIZE(FILTER('Data',[Type]=2),[Time])
var C= SUMMARIZE(FILTER('Data',[Type]=3),[Sla])
RETURN CALCULATE(COUNTROWS(A) / COUNTROWS(B) * COUNTROWS(C), FILTER(A,[Time]>MAXX(B,[Time]) &&[Sla]>MAXX(C,[Sla])))

Eyelyn9_0-1648002393089.png

 

If you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data to help us clarify your scenario.

How to Get Your Question Answered Quickly

How to provide sample data in the Power BI Forum

 

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Anonymous ,

 

Thanks for your solution - I do, however, realize that my initial question perhaps was not entirely what i really was looking for.

 

Given a table like below, could you suggest a way to calculate the difference between the time of rows with type 1 against rows with type 2 of the same Id.

 

ie. the difference between [Time] of row 1 with [Type] = 1 and [Time] of row 2 with [Type] = 2

and for rows 4 and 5 as well since they have the same Id and Type 1 and 2

 

IdTypeTime
1115-03-2022 10:00:00
1215-03-2022 11:00:00
2115-03-2022 10:00:00
3115-03-2022 10:00:00
3215-03-2022 12:00:00
4215-03-2022 13:00:00

 

To clarify, the table is logging events of different [Type] as well as the [Time] of that event and an associated [Id] of the entity producing that event. I would like to find all Id's which has an event of Type=1 AND THEN (based on Time) and event of Type=2.

 

The result should ideally be a table of Ids and Times:

 

IdType 1 TimeType 2 Time
115-03-2022 10:00:0015-03-2022 11:00:00
315-03-2022 10:00:0015-03-2022 12:00:00

 

Do you have any suggestions as to how i can achieve this?

Thanks in advance!

 

/M

amitchandak
Super User
Super User

@IvensaMDH , try like

 

Result =
VAR A = Maxx(Data, Data[Type] = 1, Data[Time])
VAR B = Maxx(Data, Data[Type] = 2, Data[Time])
VAR C = Maxx(Data, Data[Type] = 3, Data[sal])
VAR D = Maxx(Data, Data[Type] = 1, Data[sal])
RETURN CALCULATE(COUNTROWS(A) / COUNTROWS(B) * COUNTROWS(C), A > B, C < D)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.