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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
govi
Helper II
Helper II

Calculate result from two records

Hi, I am stuck....

 

I have a query with these records:

Users are asked questions during the day.
One of the questions "Have you taken your study medication TODAY?" is asked at 9:00 in the morning.
-If they answer "No" the same question will be asked again at 12:00
-If the don't answer the question ("notAnswered") the same question will be asked again at 12:00
-If they answer "Yes" nothing happens at 12:00 (but the question will be in the records with "FALSE" in column "needToAnswer"

 

The next day it starts again at 9:00

The records in the query contain other questions and answers and questions and answers from other users.

The column "Outcome for that day" show the outcome of the 2 questions for that day for that user (this is a fictional column)

 

I want to be able to calculate the definitive answer every "questionDay" per user. And create a visual of that.

 

I have attached an example of the query and a example of the visual I want to make.

 

Thanks a lot in advance, I am totally lost...

govi

 

Query:

govi_0-1704555813083.png

Visual:

govi_2-1704555869516.png

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@govi 

I have created a column to calculate the outcome, let me know how the percentage should b calucated if you need help.

Outcome = 
VAR __userid = Table1[userld]
VAR __questionday = Table1[question Day]
VAR __T = CALCULATETABLE( VALUES( Table1[Answer]), Table1[userld] = __userid, Table1[question Day] = __questionday, REMOVEFILTERS() )
VAR __Y = "Yes"
VAR __N = "No"
VAR __NA = "n/a"
VAR __NotA = "not answered"
VAR __RESULT = 
    SWITCH(
        TRUE(),
        __Y in __T , __Y,
        NOT __Y in __T && __N IN __T ,  __N,
        COUNTROWS(__T) = 1 && __NotA IN __T , __NotA
    )
RETURN
    __RESULT

 

Fowmy_0-1704626146902.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@govi 

I have created a column to calculate the outcome, let me know how the percentage should b calucated if you need help.

Outcome = 
VAR __userid = Table1[userld]
VAR __questionday = Table1[question Day]
VAR __T = CALCULATETABLE( VALUES( Table1[Answer]), Table1[userld] = __userid, Table1[question Day] = __questionday, REMOVEFILTERS() )
VAR __Y = "Yes"
VAR __N = "No"
VAR __NA = "n/a"
VAR __NotA = "not answered"
VAR __RESULT = 
    SWITCH(
        TRUE(),
        __Y in __T , __Y,
        NOT __Y in __T && __N IN __T ,  __N,
        COUNTROWS(__T) = 1 && __NotA IN __T , __NotA
    )
RETURN
    __RESULT

 

Fowmy_0-1704626146902.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi @Fowmy ,

This is exactly what I needed! Thank you!

govi
Helper II
Helper II

I forgot a column: both questions have a unique "questionId"

govi_0-1704565662019.png

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.