Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Dynamically display sections and their details based on selected audit in Power BI

Hi, I'm working on an audit report in Power BI.

I have a slicer for selecting auditoria_id, and within each audit, there are several sections (Sección.nombre, like "SECTION 1", "FINAL SECTION", etc.).

I would like that when I select one audit, it dynamically displays only the sections that belong to that audit, and for each section, a header with its name followed by its related questions and answers.

For example:

If audit 10 has 3 sections, I want to see 3 blocks: one for each section with its questions and answers.

If another audit has only 2 sections, then only those two should appear.

Is it possible to do this dynamically in Power BI without creating one visual per section manually?

Thank you very much!

  • Let’s assume you have the following tables:

    Table

    Key Columns

    Auditorias

    auditoria_id

    Secciones

    seccion_id, nombre, auditoria_id

    Preguntas

    pregunta_id, texto, seccion_id

    Respuestas

    pregunta_id, respuesta, auditoria_id (or linked indirectly)

    1. Add a slicer for auditoria_id

    Place a slicer on the page using the auditoria_id field from your Auditorias table.

    1. Create a calculated column for grouping display

    If you want to show section headers within a table or matrix visual, Power BI doesn’t support visual-level grouping like that. But we can simulate it.

    Create a calculated column in your Preguntas table:

    DisplayText =

    "[" & RELATED(Secciones[nombre]) & "] " & Preguntas[texto]

    This gives you:
    [SECTION 1] What is your name?
    [FINAL SECTION] Any comments?

    1. Use a Table Visual (Simulated Header Grouping)

    In a Power BI Table visual:

    • Add Secciones[nombre] as the first column
    • Then add:
      • Preguntas[texto]
      • Respuestas[respuesta]

    Apply sorting by:

    1. Secciones[nombre]
    2. Preguntas[texto]

    Then it will group by section automatically (with no manual visuals), like this:

    Section Name

    Question

    Answer

    SECTION 1

    What is your name?

    John

    SECTION 1

    Age?

    25

    FINAL SECTION

    Any comments?

    None

    Use Matrix Visual for Collapsible Sections

    If you want collapsible sections:

    • Use a Matrix visual
    • Rows:
      • Secciones[nombre]
      • Preguntas[texto]
    • Values:
      • Respuestas[respuesta]

    Now, each section becomes expandable/collapsible automatically.

     

  • Hi Anonymous , Thank you for reaching out to the Microsoft Community Forum.

     

    Let us assume you have four tables: Audits:

    AuditID (PK)

    AuditName

    Date

     

    1

    Safety Audit

    2024-01-15

     

    2

    Compliance Check

    2024-02-03

     

     Sections:

    SectionID (PK)

    AuditID (FK)

    SectionName

    10

    1

    General Info

    11

    1

    Final Comments

    12

    2

    Compliance Items

    Questions:

    QuestionID (PK)

    SectionID (FK)

    QuestionText

    100

    10

    What is your name?

    101

    10

    What is your role?

    102

    11

    Any final remarks?

    Answers:

    AnswerID (PK)

    QuestionID (FK)

    AuditID (FK)

    Answer

    1000

    100

    1

    John Smith

    1001

    101

    1

    Inspector

    1002

    102

    1

    All good

     

    Then, make sure your data model has these relationships: Audits[AuditID] -> Sections[AuditID], Sections[SectionID] -> Questions[SectionID], Questions[QuestionID] -> Answers[QuestionID]

     

    If answers are tied to a specific audit, include AuditID in the Answers table and link it to Audits[AuditID]. All relationships must be active and properly defined in Power BI's model view. Create the below DAX measure:

    AnswerText =

    CONCATENATEX(

        VALUES(Answers[Answer]),

        Answers[Answer],

        ", "

    )

     

    Add a slicer to your report using Audits[AuditID]. This filters the report to show only data related to the selected audit. Then, insert a Matrix visual. In the Rows, add Sections[SectionName] followed by Questions[QuestionText]. In Values, add the AnswerText measure. Finally, go to the Matrix formatting pane and enable “Stepped layout” under Row headers to clearly indent questions under each section.

     

    If this helped solve the issue, please consider marking it “Accept as Solution” and giving a ‘Kudos’ so others with similar queries may find it more easily. If not, please share the details, always happy to help.
    Thank you.

5 Replies

  • Let’s assume you have the following tables:

    Table

    Key Columns

    Auditorias

    auditoria_id

    Secciones

    seccion_id, nombre, auditoria_id

    Preguntas

    pregunta_id, texto, seccion_id

    Respuestas

    pregunta_id, respuesta, auditoria_id (or linked indirectly)

    1. Add a slicer for auditoria_id

    Place a slicer on the page using the auditoria_id field from your Auditorias table.

    1. Create a calculated column for grouping display

    If you want to show section headers within a table or matrix visual, Power BI doesn’t support visual-level grouping like that. But we can simulate it.

    Create a calculated column in your Preguntas table:

    DisplayText =

    "[" & RELATED(Secciones[nombre]) & "] " & Preguntas[texto]

    This gives you:
    [SECTION 1] What is your name?
    [FINAL SECTION] Any comments?

    1. Use a Table Visual (Simulated Header Grouping)

    In a Power BI Table visual:

    • Add Secciones[nombre] as the first column
    • Then add:
      • Preguntas[texto]
      • Respuestas[respuesta]

    Apply sorting by:

    1. Secciones[nombre]
    2. Preguntas[texto]

    Then it will group by section automatically (with no manual visuals), like this:

    Section Name

    Question

    Answer

    SECTION 1

    What is your name?

    John

    SECTION 1

    Age?

    25

    FINAL SECTION

    Any comments?

    None

    Use Matrix Visual for Collapsible Sections

    If you want collapsible sections:

    • Use a Matrix visual
    • Rows:
      • Secciones[nombre]
      • Preguntas[texto]
    • Values:
      • Respuestas[respuesta]

    Now, each section becomes expandable/collapsible automatically.

     

  • v-hashadapu's avatar
    v-hashadapu
    Icon for Community Support rankCommunity Support

    Hi Anonymous , Thank you for reaching out to the Microsoft Community Forum.

     

    Let us assume you have four tables: Audits:

    AuditID (PK)

    AuditName

    Date

     

    1

    Safety Audit

    2024-01-15

     

    2

    Compliance Check

    2024-02-03

     

     Sections:

    SectionID (PK)

    AuditID (FK)

    SectionName

    10

    1

    General Info

    11

    1

    Final Comments

    12

    2

    Compliance Items

    Questions:

    QuestionID (PK)

    SectionID (FK)

    QuestionText

    100

    10

    What is your name?

    101

    10

    What is your role?

    102

    11

    Any final remarks?

    Answers:

    AnswerID (PK)

    QuestionID (FK)

    AuditID (FK)

    Answer

    1000

    100

    1

    John Smith

    1001

    101

    1

    Inspector

    1002

    102

    1

    All good

     

    Then, make sure your data model has these relationships: Audits[AuditID] -> Sections[AuditID], Sections[SectionID] -> Questions[SectionID], Questions[QuestionID] -> Answers[QuestionID]

     

    If answers are tied to a specific audit, include AuditID in the Answers table and link it to Audits[AuditID]. All relationships must be active and properly defined in Power BI's model view. Create the below DAX measure:

    AnswerText =

    CONCATENATEX(

        VALUES(Answers[Answer]),

        Answers[Answer],

        ", "

    )

     

    Add a slicer to your report using Audits[AuditID]. This filters the report to show only data related to the selected audit. Then, insert a Matrix visual. In the Rows, add Sections[SectionName] followed by Questions[QuestionText]. In Values, add the AnswerText measure. Finally, go to the Matrix formatting pane and enable “Stepped layout” under Row headers to clearly indent questions under each section.

     

    If this helped solve the issue, please consider marking it “Accept as Solution” and giving a ‘Kudos’ so others with similar queries may find it more easily. If not, please share the details, always happy to help.
    Thank you.

  • v-hashadapu's avatar
    v-hashadapu
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,
    I wanted to follow up and see if you’ve had a chance to review the information provided here.
    If any of the responses helped solve your issue, please consider marking it "Accept as Solution" and giving it a 'Kudos' to help others easily find it.
    Let me know if you have any further questions!

  • v-hashadapu's avatar
    v-hashadapu
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,
    I hope the information shared was helpful. If you have any additional questions or would like to explore the topic further, feel free to reach out. If any of the responses resolved your issue, please mark it "Accept as solution" and give it a 'Kudos' to support other members in the community.
    Thank you!

  • v-hashadapu's avatar
    v-hashadapu
    Icon for Community Support rankCommunity Support

    Hi Anonymous , Just checking in—were you able to resolve the issue?
    If one of the replies helped, please consider marking it as "Accept as Solution" and giving a 'Kudos'. Doing so can assist other community members in finding answers more quickly.
    Thank you!