Forum Discussion

srpeters's avatar
srpeters
Icon for Helper II rankHelper II
2 years ago
Solved

DAX function not working in power query column

I have a column that displays what generation people fall under based off of their birth year. I want to also display the total percentage of those who fall into this catagory. I made this DAX to do ...
  • 123abc's avatar
    2 years ago

    It seems like you're trying to calculate the percentage of Baby Boomers within your dataset. However, the DAX expression you provided seems a bit off for achieving that within Power Query, as it's typically used in Power BI or Excel.

    To calculate the percentage of Baby Boomers within your dataset in Power Query, you can follow these steps:

    1. Create a new column in your Power Query editor.
    2. Use the following M language code to calculate the percentage of Baby Boomers:

    = if [Year] >= 1946 and [Year] <= 1964 then 1 else 0

    This code will create a binary column where 1 represents individuals who fall under the Baby Boomer category based on the birth year and 0 represents others.

    1. Once you have this binary column, you can then calculate the percentage of Baby Boomers using the following steps:
    • Go to the Home tab in the Power Query Editor.
    • Click on the "Group By" option.
    • Select the column containing the binary values (1s and 0s).
    • Choose to group by the column.
    • Add an aggregation operation to calculate the percentage (you can choose to sum the binary values and then divide by the total count).

    This should give you the correct percentage of Baby Boomers within your dataset without affecting the conditional statement used for the generation column. Make sure to adjust the column names and conditions according to your actual dataset structure.

     

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

     

    In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.