Forum Discussion

IcingOnTheCake's avatar
IcingOnTheCake
Icon for Helper III rankHelper III
5 years ago
Solved

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

12 Replies

    • IcingOnTheCake's avatar
      IcingOnTheCake
      Icon for Helper III rankHelper III

      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's avatar
        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  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?

  • 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