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
R0bson
Frequent Visitor

how to prepare measure that relates to a "temp table"

Hi,

I have problem to prepare calulation in PBI that gives me the same result like simple sql code below:

 

SELECT clid
into #qs"
FROM queue_stats_mv
where date between StartDate and EndDate
group by clid
having count(distinct datetime)>1

select count(*)
from queue_stats_mv
where date between StartDate and EndDate and clid not in (select clid from #qs)

I tried calculate something that gives me similary result like temp table #qs using calculatetable and summarize to create new table and define relations between new calculate table and queue_stats_mv but it doesn't work. I need prepare this calculation base on dynamic dates range from date filter in table queue_stats_mv. Any suggestions?

1 ACCEPTED SOLUTION

You may be overcomplicating things a bit.  Let the data model do the work for you.

 

Measure with slicer date range = 
var a = selectcolumns(CALCULATETABLE(
    Filter(SUMMARIZE(
            queue_stats_mv,
            queue_stats_mv[clid],
            "qty", COUNTROWS(queue_stats_mv)
    ),
    [qty] > 1
    ),
    queue_stats_mv[event] in {"ABAN","AGENT_D"}
    ),"clid",[clid])
return   CALCULATE(
COUNTROWS(queue_stats_mv),
NOT queue_stats_mv[clid] IN a,queue_stats_mv[event] in {"COMPLETE_C","COMPLETE_A"})

 

see attached. I removed all the unnecessary tables and added a necessary dates table.

View solution in original post

4 REPLIES 4
R0bson
Frequent Visitor

Hi, thanks for reply.

You can see 2 measures in PBI sample:
Measure with fixed date range - i put fixed date range in calculatetable and measure and this give me correct result 5082.
Measure with slicer date range- this is my measure that i need change something to use dynamic date range from slicer.
I expected the same result as in measure with fixed date range in period: 2023-03-01 - 2023-03-14 but using slicer.

https://drive.google.com/file/d/1arZ4re3DBcxeCGNPeZKNYxdpmDpzbNIQ/view

 

You may be overcomplicating things a bit.  Let the data model do the work for you.

 

Measure with slicer date range = 
var a = selectcolumns(CALCULATETABLE(
    Filter(SUMMARIZE(
            queue_stats_mv,
            queue_stats_mv[clid],
            "qty", COUNTROWS(queue_stats_mv)
    ),
    [qty] > 1
    ),
    queue_stats_mv[event] in {"ABAN","AGENT_D"}
    ),"clid",[clid])
return   CALCULATE(
COUNTROWS(queue_stats_mv),
NOT queue_stats_mv[clid] IN a,queue_stats_mv[event] in {"COMPLETE_C","COMPLETE_A"})

 

see attached. I removed all the unnecessary tables and added a necessary dates table.

Thank You very much. Your solution is very simple and efficiency !

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.