Forum Discussion
Netdog2001ta
2 years agoFrequent Visitor
Problem with DAX Formula
Hi, I'm a Newbie in Power Bi and I'm trying to write a DAX formula to retrieve a date and a price from two tables. The first table has this structure: ArticoloEtichetta Descrizione Qta Dat...
Netdog2001ta
2 years agoFrequent Visitor
Hi mark_endicott , before of all Thanks for the support, I've changed the tables references and created the calculated column but it gives me an error that I don't understand:
A table of multiple values was specified when a single value was expected.
The lookuptable is a historic recording of price changes of products and in the same date can be multiple product price changes.
The base table is a document tables with purchase and selling values(that i filter in Power Bi).
Here is a screenshot:
Only for yolur information the BaseTable Date can be retrieved from another table related to basetable.
Here is the code adapted to my work:
Purchase Price =
VAR _date = documentidettaglio[DataProtocollo]
VAR _prod_code = documentidettaglio[ArticoloEtichetta]
VAR prev_date_table =
CALCULATETABLE (
ADDCOLUMNS ( Storico_Test_1, "max_date", MAX ( Storico_Test_1[Data] ) ),
Storico_Test_1[Data] < _date,
Storico_Test_1[ArticoloEtichetta] = _prod_code
)
VAR prev_date =
MAXX ( prev_date_table, [max_date] )
VAR look_up =
LOOKUPVALUE (
Storico_Test_1[Acquisto Netto],
Storico_Test_1[ArticoloEtichetta], documentidettaglio[ArticoloEtichetta],
Storico_Test_1[Data], documentidettaglio[DataProtocollo]
)
RETURN
IF (
ISBLANK ( look_up ),
CALCULATE (
MAX ( Storico_Test_1[Acquisto Netto] ),
Storico_Test_1[ArticoloEtichetta] = _prod_code
&& Storico_Test_1[Data] = prev_date
),
look_up
)Thanks in advance for all your support