Forum Discussion
How do I do this? Variable table, limiting data based on selection
- 3 years ago
Anonymous With regard to your question above you can store a variable and use it as a filter in another table like:
Measure = VAR __table = SELECTCOLUMNS('Table',"FilterColumn",[Column]) VAR __filteredTable = FILTER('Table2',[Some Column] IN __table)
Hi Anonymous ,
Bacause you do not provide a screenshot of the results you are expecting and desensitized example data, I could only according to your descriptions to give some suggestions, please try below dax formula, do some adjustments according to your measure:
O QTY OD FLOW =
VAR bob =
SELECTEDVALUE ( DateRanges[daterangeid] )
VAR origin =
SELECTEDVALUE ( 'PrimaryMarketTable ODflow'[PrimaryMarket] )
VAR test =
CALCULATE (
[O QTY L4wks removed origin city from dest OD flow],
TOPN (
5,
ALLSELECTED ( 'OD CitytoCityOrigin'[PrimaryMarketDest] ),
[O QTY L4wks removed origin city from dest OD flow], DESC
),
VALUES ( 'OD CitytoCityOrigin'[PrimaryMarketdest] ),
FILTER (
ALL ( 'OD CitytoCityOrigin' ),
'OD CitytoCityOrigin'[PrimaryMarketOrigin] = origin
)
)
VAR jim =
LOOKUPVALUE (
'OD CitytoCityOrigin'[PrimaryMarketDest],
'OD CitytoCityOrigin'[PrimaryMarketOrigin], origin,
test
)
VAR third =
CALCULATETABLE (
VALUES ( 'OD CitytoCityOrigin'[PrimaryMarketDest] ),
FILTER ( ALL ( 'OD CitytoCityOrigin' ), jim <> BLANK () )
)
VAR secondtake =
CALCULATE (
[O QTY L4wks removed origin city from dest OD flow],
TOPN (
5,
ALLSELECTED ( 'OD CitytoCityOrigin'[PrimaryMarketDest] ),
[O QTY L4wks removed origin city from dest OD flow], DESC
),
VALUES ( 'OD CitytoCityOrigin'[PrimaryMarketdest] ),
FILTER (
ALL ( 'OD CitytoCityOrigin' ),
'OD CitytoCityOrigin'[PrimaryMarketOrigin] IN third
)
)
RETURN
secondtake
Thanks for your efforts & time in advance.
Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you for your response, but I am still not there. In your previous post you fixed my query (kind of) - the All ( 'OD CitytoCityOrigin' ) - this messes things up as it ends up grabbing the entire table. I removed the All and it somewhat works.
This is where I am at now - This one errors with "A function "PLACEHOLDER' has been used in a True/False expression that is used as a table filter expression."
OK - TEST1 gives me my top 10 cities that we sent trucks to. I then need to combine that Test1 with those 10 destination cities now as the origin.
Accroding to Dax Formatter - this query currently has a syntax error, but it isn't caught by power bi, so maybe not. That syntax error is supposed to be here:
var DestCitiestable =
CALCULATEtable ('OD CitytoCityOrigin',
[O QTY L4wks removed origin city from dest OD flow], <--- HERE before the comma
TOPN (
10,
ALLSELECTED ( 'OD CitytoCityOrigin'[PrimaryMarketDest] ),
[O QTY L4wks removed origin city from dest OD flow], DESC
),
VALUES ( 'OD CitytoCityOrigin'[PrimaryMarketdest] ),
FILTER (
'OD CitytoCityOrigin' ,
'OD CitytoCityOrigin'[PrimaryMarketOrigin] = origin && 'OD CitytoCityOrigin'[OriginQTY]>0 )
)
Here is the full code, this does not work.
O QTY L4wks OD FLOW =
VAR bob =
SELECTEDVALUE ( DateRanges[daterangeid] )
VAR origin =
SELECTEDVALUE ( 'PrimaryMarketTable ODflow'[PrimaryMarket] )
VAR test1 =
CALCULATE (
calculate([O QTY L4wks removed origin city from dest OD flow],FILTER (
'OD CitytoCityOrigin' ,
'OD CitytoCityOrigin'[PrimaryMarketOrigin] = origin && 'OD CitytoCityOrigin'[OriginQTY]>0
)),
TOPN (
10,
ALLSELECTED ( 'OD CitytoCityOrigin'[PrimaryMarketDest] ),
[O QTY L4wks removed origin city from dest OD flow], DESC
),
VALUES ( 'OD CitytoCityOrigin'[PrimaryMarketdest] ),
FILTER (
'OD CitytoCityOrigin' ,
'OD CitytoCityOrigin'[PrimaryMarketOrigin] = origin && 'OD CitytoCityOrigin'[OriginQTY]>0 )
)
var DestCitiestable =
CALCULATEtable ('OD CitytoCityOrigin',
[O QTY L4wks removed origin city from dest OD flow],
TOPN (
10,
ALLSELECTED ( 'OD CitytoCityOrigin'[PrimaryMarketDest] ),
[O QTY L4wks removed origin city from dest OD flow], DESC
),
VALUES ( 'OD CitytoCityOrigin'[PrimaryMarketdest] ),
FILTER (
'OD CitytoCityOrigin' ,
'OD CitytoCityOrigin'[PrimaryMarketOrigin] = origin && 'OD CitytoCityOrigin'[OriginQTY]>0 )
)
var summarizeDestTable =
ADDCOLUMNS(
SUMMARIZE(DestCitiestable,'OD CitytoCityOrigin'[PrimaryMarketDest],"PrimaryMarketOrigin",'OD CitytoCityOrigin'[PrimaryMarketDest]),"aColumn",1)
VAR destcities =
CALCULATE (
calculate([O QTY L4wks removed origin city from dest OD flow],FILTER (
'OD CitytoCityOrigin',
'OD CitytoCityOrigin'[PrimaryMarketOrigin] = DestCitiestable = origin && 'OD CitytoCityOrigin'[OriginQTY]>0
)),
TOPN (
5,
ALLSELECTED ( 'OD CitytoCityOrigin'[PrimaryMarketDest] ),
[O QTY L4wks removed origin city from dest OD flow], DESC
),
VALUES ( 'OD CitytoCityOrigin'[PrimaryMarketdest] ),
FILTER (
'OD CitytoCityOrigin' ,
'OD CitytoCityOrigin'[PrimaryMarketOrigin] in summarizeDestTable && 'OD CitytoCityOrigin'[OriginQTY]>0 )
)
RETURN
destcitiesAgain, I am not looking for you to fix my syntax, or make this query work - I am hoping you can help me understand how to do what I am trying to do in my two variables "SummarizeDestTable" and "Destcities" - here I am trying to limit my original Test1 query, isolate to the Destination cities (just top 10), and use those dynamically as my new Origin selection to pull another top 5 from those origins.
I would rather you give me the process, than repost my code with slight improvements.
Thanks,
Jonathan