Forum Discussion
Calculate percent columns by several tables
- Anonymous1 year ago
Hi,ND1979
Thank you for your prompt response.I’m pleased to see that you are using the DAX query view for testing; it’s indeed a good method of validation. However, please note that the results returned in the query view are presented as a table, whereas the code I provided is context-based.
Here are the results I obtained in the table view on my desktop:
And here are the results from the DAX query view:
For further details, please refer to:
Deep dive into DAX query view and writing DAX queries | Microsoft Power BI Blog | Microsoft Power BI
DAX query view - Power BI | Microsoft LearnGiven the similarity to your erroneous results, I recommend creating a new calculated column.
Even if you don’t use it later, you can easily delete it by right-clicking.
Moreover, calculated tables and columns, including measures, do not affect the original data. They are not visible in Power Query, which serves as the best evidence of this. Therefore, you need not worry about creating unnecessary DAX expressions impacting your future work.
I hope my response is clear enough to help you understand the reasons behind the issue.If you have any further questions, feel free to ask!
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the reply from lbendlin , please allow me to provide another insight:
Hi, ND1979
Regarding the issue you raised, my solution is as follows:
1.First I have created the following table and the column names and data are the data you have given:
2.Next create relationships between tables:
3.Create calculated column references:
I created the following calculated column in the timecard table to compute the time difference.
diff = DATEDIFF('Timecard'[start],'Timecard'[end],HOUR)
In the project table, I established a calculated column to facilitate the call and division.
sumofp =
VAR cc =
CALCULATE (
SUM ( 'Timecard'[diff] ),
FILTER (
ALLSELECTED ( 'Timecard' ),
'Timecard'[Projects] = EARLIER ( 'Projects'[Projects ] )
)
)
RETURN
DIVIDE ( cc, 'Projects'[hour] )
Subsequently, I modified the data type of the calculated column.
4.Here's my final result, which I hope meets your requirements.
Please find the attached pbix relevant to the case.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Ciao and thank you so much for your help 👍
According to your example, I realized this code ( explain why), but I have a strange error:
- Anonymous1 year agoNot applicable
Hi, ND1979
Based on the DAX you provided, I suspect the issue may stem from your use of the EARLIER() function alongside the ALL() function. I suggest removing the ALL() function to see if that resolves the problem.
It’s also worth considering that differing table relationships could directly impact the output results.
The reason I use EARLIER() is to establish a connection between the associated fields of the two tables, allowing for data grouping and summation.
EARLIER function (DAX) - DAX | Microsoft Learn
I hope my explanation is clear enough. If you have any further questions, please feel free to reach out to us.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- ND19791 year agoFrequent Visitor
Hi @v-linyulu-msft ,
Thanks a lot for your feedback.
I used ALL because PowerBI DAX query said that the table\field does not exist and it's not true, as you can see in this screenhot. With ALL, i can select the table\field but then the result is always the same
- Anonymous1 year agoNot applicable
Hi,ND1979
Thank you for your prompt response.I’m pleased to see that you are using the DAX query view for testing; it’s indeed a good method of validation. However, please note that the results returned in the query view are presented as a table, whereas the code I provided is context-based.
Here are the results I obtained in the table view on my desktop:
And here are the results from the DAX query view:
For further details, please refer to:
Deep dive into DAX query view and writing DAX queries | Microsoft Power BI Blog | Microsoft Power BI
DAX query view - Power BI | Microsoft LearnGiven the similarity to your erroneous results, I recommend creating a new calculated column.
Even if you don’t use it later, you can easily delete it by right-clicking.
Moreover, calculated tables and columns, including measures, do not affect the original data. They are not visible in Power Query, which serves as the best evidence of this. Therefore, you need not worry about creating unnecessary DAX expressions impacting your future work.
I hope my response is clear enough to help you understand the reasons behind the issue.If you have any further questions, feel free to ask!
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.