cancel
Showing results for
Did you mean:
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.

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?

1 ACCEPTED SOLUTION
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:

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

3 REPLIES 3
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:

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

Community Support

Hi @key_to ,

What do you want to calculate?

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

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.

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.

Thank you,

Vishesh Jain

Announcements

#### 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.

#### 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!

#### Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

#### Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors