Forum Discussion
Dax measure formula
I have a file that contains columns (item, item_description, opening time, position, center). I want to calculate key to_bs which is equal to opening time of each article on total opening time for poste=bs and center=gias1. example:
code description item open time item key to_bs
PFGX092 GOLDINA Dry 9.5kg Africa 8.9163 6.70%=8.9163/133.16498
PFLX025 LAZIZA Dry 9.5kg 3.416 2.57%=3.416/133.16498
PFLX042 LAZIZA 9.5kg Congo 120.83268 90.74%=120.83268/133.16498
Total opening time =133.16498
- Anonymous1 year ago
Thanks for the reply from HarshSathwara19 , Kedar_Pande and rajendraongole1 , please allow me to provide another insight:
Hi nesrinehal20 ,You can use the allselected() function to dynamically get the values after filtering.
ALLSELECTED function (DAX) - DAX | Microsoft Learn
The ALLSELECTED function gets the context that represents all rows and columns in the query, while keeping explicit filters and contexts other than row and column filters. This function can be used to obtain visual totals in queries.
Here are the steps you can follow:
1. Create measure.
Measure = var _allsum= SUMX(ALLSELECTED('Table'),[open time item]) return DIVIDE( SUM('Table'[open time item]),_allsum)2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
6 Replies
- rajendraongole1
Super User
Hi nesrinehal20 - Create a measure to calculate the total opening time for poste = bs and center = gias1
Total Opening Time =
CALCULATE(
SUM('Table'[open time item]),
'Table'[poste] = "bs",
'Table'[center] = "gias1"
)Create another measure to calculate the key to_bs for each row
Key to_bs =
DIVIDE(
SUM('Table'[open time item]),
[Total Opening Time]
)In the Fields pane, select the Key to_bs measure.
Under the Modeling tab, change the format to Percentage.Hope this works, please check.
- nesrinehal20Frequent Visitor
doesn't work, 100% cle for all the articles
- Kedar_Pande
Super User
Create a calculated column:
Key to_bs =
VAR TotalOpeningTime = 133.16498
RETURN
DIVIDE('YourTable'[opening time], TotalOpeningTime, 0)💡 If this helped, please give Kudos 👍 or mark it as a Solution ✅.
Best regards,
Kedar
🌐 Connect on LinkedIn- nesrinehal20Frequent Visitor
the total opening time value is not a fixed value to make it in variable. it changes depending on center and position.
- HarshSathwara19
Helper I
Hy Man, Try this
Step 1: Total Opening Time
Create a measure for the Total Opening Time that applies the filter position = "bs" and center = "gias1".DAX
Copy code
TotalOpeningTime_bs =
CALCULATE(
SUM('Table'[opening time]),
'Table'[position] = "bs",
'Table'[center] = "gias1"
)
Step 2: Key to_bs
Create a calculated column to compute the key to_bs for each row:DAX
Copy code
key_to_bs =
IF(
AND(
'Table'[position] = "bs",
'Table'[center] = "gias1"
),
DIVIDE(
'Table'[opening time],
[TotalOpeningTime_bs]
),
BLANK()
)Best Regards,
HSathwara.If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- AnonymousNot applicable
Thanks for the reply from HarshSathwara19 , Kedar_Pande and rajendraongole1 , please allow me to provide another insight:
Hi nesrinehal20 ,You can use the allselected() function to dynamically get the values after filtering.
ALLSELECTED function (DAX) - DAX | Microsoft Learn
The ALLSELECTED function gets the context that represents all rows and columns in the query, while keeping explicit filters and contexts other than row and column filters. This function can be used to obtain visual totals in queries.
Here are the steps you can follow:
1. Create measure.
Measure = var _allsum= SUMX(ALLSELECTED('Table'),[open time item]) return DIVIDE( SUM('Table'[open time item]),_allsum)2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly