Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Percentage of confirmations in in DirectQUERY

Hi All,

I have a certain case to solve that is easily solved in regular DAX, while it is highly problematic in DircetQUERY.

Having the following column consisting of "Y" and "N", answering the question of whether the process is correct - Y, or not correct - "N".

Klimeluk_0-1638363260759.png

 

 

 The column above is linked through "SEQ" to the questions for which the answer is given. concerns.

Klimeluk_1-1638363352829.png

Additionally, each question is confirmed by several shifts (4) throughout the day.

I would like to create a new measure/column that shows the percentage of positive confirmations to a given question. Over some time.

Explanation: In a week, a question was confirmed 12 times as positive and 8 times as negative. What I want to get is the % of positive confirmations of the process of a given question.

 

In DAX I have :
Test = CALCULATE( COUNTROWS(Test), FILTER(Test,Test[OKNOTOK]=EARLIER(Test[OKNOTOK])))

% = Test[Test]/COUNTROWS(Test)

Klimeluk_2-1638363654485.png

 

Thank you for your help,
Lukasz

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

What's your expected result?  Is there any relationship created between tables CONFIRMATIONOPERATION,CONFIRMATIONS and TBLSHIFT? Which column is indicating the "question"? Are you trying to get a positive percentage for each question? For example, for question A, where the positive times is 12 and the negative times is 8, then the percentage of positive for question A is 12/(12+8)=0.6? I created a sample pbix file(see attachment), please check whether that is what you want...

1. Create sample tables

Sample dataSample dataSample dataSample data

2. Create relationships among tables

RelationshipsRelationships

3. Create a measure as below

 

% = 
VAR _positive =
    CALCULATE (
        COUNT ( 'CONFIRMATIONS'[OKNOTOK] ),
        FILTER (
            'CONFIRMATIONS',
            'CONFIRMATIONS'[SHIFTTEAMID] = SELECTEDVALUE ( 'TBLSHIFT'[ID] )
                && 'CONFIRMATIONS'[OKNOTOK] = "Y"
        )
    )
VAR _all =
    CALCULATE (
        COUNT ( 'CONFIRMATIONS'[OKNOTOK] ),
        FILTER (
            'CONFIRMATIONS',
            'CONFIRMATIONS'[SHIFTTEAMID] = SELECTEDVALUE ( 'TBLSHIFT'[ID] )
        )
    )
RETURN
    DIVIDE ( _positive, _all, 0 )

 

yingyinr_2-1638958411681.png

If the above measure is not working in your scenario, please share the required information(sample data with Text format, backend logic and expected result etc..) with me. Later I will provide you a suitable solution base on your provided information. Thank you.

Best Regards

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

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , In direct query you need to create it like measure

 

Test measure = CALCULATE( COUNTROWS(Test), FILTER(allselected(Test),Test[OKNOTOK]=max(Test[OKNOTOK])))

% = Divide(Sum(Test[Test]),[Test Measure])

Anonymous
Not applicable

Hi! Thank you for your answer 🙂 

Actually the "measure" function works when creating new measures.

However, I still have a problem. Maybe on actual data it will be easier for me to understand.

So: I'm based on 3 tables. Each connected to the other.

1. CONFIRMATIONOPERATION
Klimeluk_0-1638447012195.png

2. CONFIRMATIONS

Klimeluk_1-1638447072461.png

2. TBLSHIFT

Klimeluk_2-1638447116766.png

I created 2 measuers:
1: Measure = CALCULATE(COUNTROWS(CONFIRMATIONS),FILTER(ALLSELECTED(CONFIRMATIONS),CONFIRMATIONS[OKNOTOK]=MAX(CONFIRMATIONS[OKNOTOK])))

2: % = [Measure]/COUNTROWS(CONFIRMATIONS)


Results:

Klimeluk_3-1638447443311.pngKlimeluk_4-1638447461680.pngKlimeluk_5-1638447477722.pngKlimeluk_6-1638447506177.png

 

Where's the problem? Thank you for your support

Hi @Anonymous ,

What's your expected result?  Is there any relationship created between tables CONFIRMATIONOPERATION,CONFIRMATIONS and TBLSHIFT? Which column is indicating the "question"? Are you trying to get a positive percentage for each question? For example, for question A, where the positive times is 12 and the negative times is 8, then the percentage of positive for question A is 12/(12+8)=0.6? I created a sample pbix file(see attachment), please check whether that is what you want...

1. Create sample tables

Sample dataSample dataSample dataSample data

2. Create relationships among tables

RelationshipsRelationships

3. Create a measure as below

 

% = 
VAR _positive =
    CALCULATE (
        COUNT ( 'CONFIRMATIONS'[OKNOTOK] ),
        FILTER (
            'CONFIRMATIONS',
            'CONFIRMATIONS'[SHIFTTEAMID] = SELECTEDVALUE ( 'TBLSHIFT'[ID] )
                && 'CONFIRMATIONS'[OKNOTOK] = "Y"
        )
    )
VAR _all =
    CALCULATE (
        COUNT ( 'CONFIRMATIONS'[OKNOTOK] ),
        FILTER (
            'CONFIRMATIONS',
            'CONFIRMATIONS'[SHIFTTEAMID] = SELECTEDVALUE ( 'TBLSHIFT'[ID] )
        )
    )
RETURN
    DIVIDE ( _positive, _all, 0 )

 

yingyinr_2-1638958411681.png

If the above measure is not working in your scenario, please share the required information(sample data with Text format, backend logic and expected result etc..) with me. Later I will provide you a suitable solution base on your provided information. Thank you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thank you very much for your help. The solution is correct. Thank you all for your involvement!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.