简体   繁体   中英

Count one answer based based on a distinct code in power bi

I have a single query that populates a table as follows

ID   | Code  | Question  | Answer
INC  | 2020  | 1456      | Yes
INC  | 2020  | 1452      | Yes
INC  | 2023  | 1234      | Yes
INC  | 1984  | 5555      | Yes
KZM  | 1543  | 1456      | Yes
KZN  | 1547  | 2222      | Yes

I am new to powerbi so i would like to know how do i Count the number of answers Based on the code per an ID

for example as you can See i have an ID of INC and i have two codes of 2020 for INC. So if i have multiple of the same Code for an ID, i only want to Count 1 answer per the code

for example my expected output for ID INC should be a count of 3 Answers and my expected output for ID KZM should be count of 2 answers

My objective is to count only 1 answer per code. how do i create a measure to do this?

I need it as a measure so that i can use this measure to perform a different task

output

ID  |  Count
INC | 3
KZM | 2

You can write measure like that:

NoOfAnswers =
CALCULATE (
    COUNTROWS ( SUMMARIZE ( Tab1, Tab1[ID], Tab1[Code] ) ),
    FILTER ( ALL ( Tab1 ), Tab1[ID] = SELECTEDVALUE ( Tab1[ID] ) )
)

在此处输入图片说明

If you put the ID column in a table or matrix visual, then counting the codes should be as simple as writing a measure like this

CodeCount = DISTINCTCOUNT ( Table1[Code] )

Note that using COUNT instead of DISTINCTCOUNT would count the number of rows, not the number of distinct codes.

Try Creating a Measure:

Measure = CALCULATE(DISTINCTCOUNT('Table'[Code]),ALLEXCEPT('Table','Table'[Site ID]))

Let me know if that's the output you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM