Forum Discussion
Can' assign table elements to variables
Hi guys,
i am trying to assign for example VAR test = 'Query1'[Field] but it doesn' work. Erorr is can't find name 'Field' but i know for a fact that it exists and i'm not spelling it wrong. Can anybody help me with this?
Thank you.
25 Replies
- some_bihCommunity Champion
Hi IgorKaradzic probaj
VAR test =SELECTEDVALUE('Query1'[Field])
ili neku agregatnu kao MIN / MAX zavisno šta ti treba 🙂
- IgorKaradzicHelper I
Nazalost, ni ovo ne radi. Sad pored inicijalnog errora pokazuje i nov tip errora da parametar nije odgovarajuceg tipa. Zaboravio sam da napomenem da je Field polje tekstualni tip.
- some_bihCommunity Champion
Hi / pozdrav IgorKaradzic
We need more details about your model / tables / relationships between tables and columns and when you plan to use this field, to provide some possible solution.
- Dangar332Resident Rockstar
hi, IgorKaradzic
if its measure then need to provide aggregation function like
min(),max(),sum()...
so maybe try with VAR test = min('Query1'[Field])
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- IgorKaradzicHelper I
I don't need min or max. I need currently selected value.
- some_bihCommunity Champion
Hi IgorKaradzic what is your request for possible solution: calculate something and also on your example table there is no [Field] (reference to your initial post: Query1'[Field] but it doesn' work. Erorr is can't find name 'Field' )
- IgorKaradzicHelper I
That's what is says in error message. I sent you example table down bellow.
- IgorKaradzicHelper I
ID Task Responsible
Planned Start Date
Planned Finish Date
1
13.3.2024.
23.3.2024.
2
23.3.2024.
25.3.2024.
2
25.3.2024.
1.4.2024.
2
25.3.2024.
29.3.2024.
2
29.3.2024.
7.4.2024.
2
7.4.2024.
10.4.2024.
- AnonymousNot applicable
First, Thanks for some_bih and Dangar332 help.
Hi, IgorKaradzic
May I ask if you have solved this case, I noticed that no one is following your problem, you may refer to the following DAX.DAX:
Duration = DATEDIFF('Table'[Planned Start Date],'Table'[Planned Finish Date],DAY) Pre Duration = VAR _id = 'Table'[ID Task] VAR _index = 'Table'[Index] VAR _preduration = CALCULATE ( MIN ( 'Table'[Duration] ), FILTER ( 'Table', 'Table'[ID Task] = _id && 'Table'[Index] = _index - 1 ) ) RETURN _preduration Diff = VAR _id = 'Table'[ID Task] VAR _index = 'Table'[Index] VAR _sdate = 'Table'[Planned Start Date] VAR _prefdate = CALCULATE ( MAX ( 'Table'[Planned Finish Date] ), FILTER ( 'Table', 'Table'[ID Task] = _id && 'Table'[Index] < _index ) ) VAR _diff = IF ( ISBLANK ( _prefdate ), BLANK (), DATEDIFF ( _prefdate, _sdate, DAY ) ) RETURN _diff Actual Start Date = VAR _id = 'Table'[ID Task] VAR _index = 'Table'[Index] VAR _sdate = 'Table'[Planned Start Date] VAR _taskd0 = CALCULATE ( MIN ( 'Table'[Responsible Task] ), FILTER ( 'Table', 'Table'[ID Task] = _id && NOT ( ISBLANK ( 'Table'[Pre Duration] ) ) && 'Table'[Diff] <= 0 ) ) VAR _sdate1 = CALCULATE ( MIN ( 'Table'[Planned Start Date] ), FILTER ( 'Table', 'Table'[ID Task] = _id && NOT ( ISBLANK ( 'Table'[Pre Duration] ) ) && 'Table'[Responsible Task] = _taskd0 ) ) VAR _index1 = CALCULATE ( MIN ( 'Table'[index] ), FILTER ( 'Table', 'Table'[ID Task] = _id && NOT ( ISBLANK ( 'Table'[Pre Duration] ) ) && 'Table'[Responsible Task] = _taskd0 ) ) VAR _dnums = CALCULATE ( SUM ( 'Table'[Pre Duration] ), FILTER ( 'Table', 'Table'[ID Task] = _id && NOT ( ISBLANK ( 'Table'[Pre Duration] ) ) && 'Table'[Index] <= _index ) ) RETURN IF ( ISBLANK ( 'Table'[Diff] ), 'Table'[Planned Start Date], IF ( 'Table'[Responsible Task] = _taskd0, 'Table'[Planned Start Date] + [Diff] + 1, _sdate1 + _dnums + [Index] - _index1 - 1 ) ) Actual Finish Date = 'Table'[Actual Start Date]+[Duration]Best Regards,
Yang
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!How to get your questions answered quickly -- How to provide sample data in the Power BI Forum