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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
IcingOnTheCake
Helper III
Helper III

Lookup a column value thats in my Temporary Table variable

Hi experts,

 

I have the following Dax code to get "Number of ranked invoices" in certain ranges.
Now I need one more information, that I need to filter my table "Invoice" in the report. The Classification.
I dont know how to get the Classification in a table column now. I sure can see it in DAX STudio as a temporary column. But I dont know how to get it as a column that I can filter for in my report.
I'm a newbie in DAX and POwer BI. Sorry.

From the logic, I would like to make a lookupvalue() with my "Invoiceid" in the temporary table "VAR _InvoicesInClass" to get the class for each row in "Inovice" at the end. But that doesnt work somehow.
Thanks for your help!!

 

 

Table1 Invoice

Invoiceid | Price | Customer | account number | Number of ranked invoices (code below) | CLASS (from Invoice Classification; want to add that)

 

Table2 Invoice_Classification

CLass Start End Order Class Name

 

Thats the DAX code for measure "Number of ranked invoices":

 

MEASURE Invoice[Number of Ranked Invoices] =

VAR _SelectedInvoices =
ALLSELECTED( Invoice )

VAR _NumberOfSelectedInvoices =
VAR _DistinctInvoiceId =

CALCULATE( DISTINCTCOUNT( Invoice[InvoiceId] ), _SelectedInvoices )
RETURN
IF( _DistinctInvoiceId >= 10, _DistinctInvoiceId, 10 )
VAR _RankedInvoices =
ADDCOLUMNS(
_SelectedInvoices,
"@Rank", RANKX( _SelectedInvoices, [Invoices Price],, DESC, SKIP )
)

VAR _ClassificationWithRanks =

ADDCOLUMNS(Invoice_Classification
,
"@MinimumRank", Invoice_Classification[Start] * _NumberOfSelectedInvoices,
"@MaximumRank", Invoice_Classification[End]* _NumberOfSelectedInvoices
)
VAR _InvoicesInClass =
FILTER(
CROSSJOIN( _RankedInvoices, _ClassificationWithRanks ),
AND( [@Rank] > [@MinimumRank], [@Rank] <= [@MaximumRank] )
)


VAR _Result =
CALCULATE( DISTINCTCOUNT( Invoice[InvoiceId] ), KEEPFILTERS( _InvoicesInClass ) )
RETURN
_Result

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @IcingOnTheCake ,

I updated my sample file and created two measures to replace the previous calculated columns since you want to display data dynamically.

yingyinr_0-1619085131234.png

Best Regards

View solution in original post

12 REPLIES 12
IcingOnTheCake
Helper III
Helper III

Thats what I wanna do as a screenshot. I need the dax formula for the class column ( I've hardcoded the classification values as an example)
Thank you

Screenshot 2021-04-20 091121.png

IcingOnTheCake
Helper III
Helper III

Thank you  @Anonymous 

I've created a pbix file as an example, but I honestly dont know how to upload to this post. I only find image and video upload options. So sorry.
How can I upload that file?

amitchandak
Super User
Super User

@IcingOnTheCake , Are trying to filter Rank, based on slicer values ??

refer if this example can help

For Rank Refer these links

https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

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

Thank you for your fast answer!
But thats not exactly what I'm looking for.
I dont only need the Top N I need ranges.
Maybe its clearer when I post the classification table.

So I would like to show the invoice table and the classification in a column of this table.
based on whats currently filtered.

Class        Start    End Order  Class Name

Top00,11Top (10 %)
High0,10,32High (20%)
Medium0,30,63Medium (30%)
Low0,614Low (40%)
Anonymous
Not applicable

Hi @IcingOnTheCake ,

Could you please provide the original data in your model tables and expected result with calculation logic and examples? Thank you.

Best Regards

Thank you  @yingyinr 

I've created a pbix file as an example, but I honestly dont know how to upload it to this post. I only find image and video upload options. So sorry.
How can I upload that file?
Thats what I wanna do as a screenshot. I need the dax formula for the class column ( I've hardcoded the classification values as an example)
Thank you
Screenshot 2021-04-20 091121.png

Anonymous
Not applicable

Hi @IcingOnTheCake ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

yingyinr_0-1618909884686.png

In addition, you can refer the content in the following video to achieve it.

Grouping & Segmenting Your Data With DAX Measure Logic - Advanced DAX

If the above ones is not working for your scenario, please provide some sample data with Text format and your expected result with calculation logic and examples. Thank you.

Best Regards

Thank you.
In my example the "RANK" formula doesnt work correct. So the class aalso not.
I assume its because there are many more companies in the table than just in the example only "BE". As well there are several slicers that could be selected. (but it also doesn't work with all slicers set to "all".
So my question:
instead of 

FILTER(ALL('invoice'),'invoice'[Company]=EARLIER('invoice'[Company]))
how can I say: "what is currently selected for this visual. with all slicers and filters"
Thank you
Anonymous
Not applicable

Hi @IcingOnTheCake ,

I updated my sample file and created two measures to replace the previous calculated columns since you want to display data dynamically.

yingyinr_0-1619085131234.png

Best Regards

Thank you  @Anonymous that you try to help me so much! I really appreciate.

I've added your solution. But now I get that error, as soon as I add the measure "class measure"

to my table visual where the classification should be shown.
Any idea why?
IcingOnTheCake_0-1619504768762.png

 

Anonymous
Not applicable

Hi again,

ok. That unexpected error disappeared after reopening the file.


At the end the below is the solution.
I had to add one more line to your code.

Had to do this, because all filters where always (company, slicers....) ignored and only with that line:
If (isempty(invoice),blank(),..........)
it worked.

Actually I dont know why this is needed. I found it while googling but without any useful explanation. 
Can you explain, why this is needed?
Thank you and thank y for all your help with the code!

IcingOnTheCake_0-1620124565677.png

 

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.

Top Solution Authors