cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
key_to
Frequent Visitor

help creating a variable

Hello! 

I have a simple table with 'end of year' date, org unit and number of employees - see screenshot. I would like to convert all the numbers in the table below into variables so that I can use them in other calculations like turnover or growth. 

key_to_0-1665138755601.png

 

I created a dimension table with all the org units that connects the "orgenhet" in this table to the main table.  This is because I wanted to avoid to have to created a variable per org unit. I tried something like this: 

 

.LY Antall Ansatte =
VAR YEdate =
    YEAR (TODAY())-1
VAR YEansatt =
       SUMX(FactYearEnd[EoY Antall ansatte])
       FILTER (
            FactYearEnd,
            (
                YEAR('FactYearEnd'[Date])=YEdate
            )
        ))

RETURN
   YEansatt
 
I think the logic might work, but the formula is wrong. Anyone who can help me? 
 
Thanks a lot in advance!
1 ACCEPTED SOLUTION
key_to
Frequent Visitor

Hi and thanks to you both for putting me on a right path!

I was probably just thinking to complicated.  I wanted to be able to refer to the number from the table through variable and I think I achieved it simply with the calculate function: 

key_to_0-1665385154970.png

 

This looks correctly when testing. Now it remains to see whether I get the right results in my calculation of turnover and growth 🙂 

View solution in original post

3 REPLIES 3
key_to
Frequent Visitor

Hi and thanks to you both for putting me on a right path!

I was probably just thinking to complicated.  I wanted to be able to refer to the number from the table through variable and I think I achieved it simply with the calculate function: 

key_to_0-1665385154970.png

 

This looks correctly when testing. Now it remains to see whether I get the right results in my calculation of turnover and growth 🙂 

v-yinliw-msft
Community Support
Community Support

Hi @key_to ,

 

Could you please tell me more about your purpose of converting numbers to variables?

What do you want to calculate?

But the function SUMX needs two parameters and the first parameter needs to be a table:

vyinliwmsft_0-1665371726944.png

SUMX function (DAX) - DAX | Microsoft Learn

You can refer this documentation.

 

Hope this helps you.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

visheshjain
Super User
Super User

Hi @key_to,

 

Not sure what are you trying to do, but why do you need a variable for each organization?!

 

If you have created a dimension table, then create a relationship between the fact and the dimension table and use the organization as a slicer/field on your report.

 

If you are trying to get the value of the previous year of the same organization then you can use MAX() function over the dates column.

 

Please provide us more information along with a sample PBIX file.

 

Thank you,

Vishesh Jain

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.