Forum Discussion

RichOB's avatar
RichOB
Icon for Post Partisan rankPost Partisan
1 year ago

Need help creating narrative sentences where the text changes when the data updates

Hi, I saw a way ages ago for adding text to a report where the key data points change as the source data updates. I want to write the sentences below in my report using the tabled data underneath it. I need it to be more quarter specific than the information that the Smart Narrative.

 

- Total amount of Incidents grew in Q2 to Q3 by X%

- LOCATION had the highest amount of Incidents from Q2 to Q3 by X%

- INCIDENT TYPE increased from Q2 to Q3 by X% with LOCATION having the most at X%

- INCIDENT TYPE decreased from Q2 to Q3 in X by X%BY LOCATION having the biggest decrease by X%

 

Incident TypeLocationDateFinancial Quarter
Missing personGlasgow02/08/2024Q2
Missing personGlasgow02/08/2024Q2
Medical concernGlasgow01/11/2024Q3
Missing personGlasgow01/11/2024Q3
Missing personGlasgow01/11/2024Q3
Medical concernEdinburgh02/08/2024Q2
Medical concernEdinburgh02/08/2024Q2
Missing PersonEdinburgh02/08/2024Q2
Medical concernEdinburgh01/11/2024Q3
Medical concernEdinburgh01/11/2024Q3
AggressionManchester02/08/2024Q2
AggressionManchester02/08/2024Q2
AggressionManchester01/11/2024Q3
AggressionManchester01/11/2024Q3
Medical concernManchester01/11/2024Q3

 

Thanks for your help!

3 Replies

  • Hi RichOB 

    To generate the sentences dynamically based on the data provided, we can break this down into steps using DAX . Here's how to create those insights accurately:

    Steps to Implement:

    1. Prepare a Pivot Table or Summarized Data Table

      • Group the data by Incident Type, Location, and Financial Quarter.
      • Count the number of incidents for each combination.

      Example:

      Incident Type Location Financial Quarter Count
      Missing PersonGlasgowQ22
      Missing PersonGlasgowQ33
      Medical ConcernGlasgowQ31
      Medical ConcernEdinburghQ22
      Medical ConcernEdinburghQ32
      AggressionManchesterQ22
      AggressionManchesterQ32
      Medical ConcernManchesterQ31

    Key Measures:

    1. Total Growth in Incidents (Q2 to Q3):

      TotalGrowthIncidents = 
      VAR Q2Incidents = CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q2")
      VAR Q3Incidents = CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q3")
      RETURN
      DIVIDE(Q3Incidents - Q2Incidents, Q2Incidents, 0)

      Output: Calculate the % change from Q2 to Q3.

    1. Location with the Highest Growth in Incidents:

      LocationGrowth = 
      ADDCOLUMNS(
          SUMMARIZE('Table', 'Table'[Location]),
          "Growth", DIVIDE(
              CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q3") -
              CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q2"),
              CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q2"), 0
          )
      )
      RETURN TOPN(1, LocationGrowth, [Growth], DESC)

      Output: Location with the highest percentage growth.

    1. Incident Type with the Highest Increase:

      IncidentTypeGrowth = 
      ADDCOLUMNS(
          SUMMARIZE('Table', 'Table'[Incident Type]),
          "Growth", DIVIDE(
              CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q3") -
              CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q2"),
              CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q2"), 0
          )
      )
      RETURN TOPN(1, IncidentTypeGrowth, [Growth], DESC)

      Output: Incident type with the highest percentage growth and associated location.

    1. Incident Type with the Largest Decrease:

      IncidentTypeDecrease = 
      ADDCOLUMNS(
          SUMMARIZE('Table', 'Table'[Incident Type]),
          "Decrease", DIVIDE(
              CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q3") -
              CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q2"),
              CALCULATE(SUM('Table'[Count]), 'Table'[Financial Quarter] = "Q2"), 0
          )
      )
      RETURN TOPN(1, IncidentTypeDecrease, [Decrease], ASC)

      Output: Incident type with the largest percentage decrease and associated location.

    Narrative Example Output:

    Once you've calculated the measures, use Smart Narrative or custom text boxes in Power BI to display the dynamic sentences. Example:

    • "The total amount of incidents grew in Q2 to Q3 by 20%."
    • "Glasgow had the highest amount of incidents from Q2 to Q3, growing by 25%."
    • "Medical concern incidents increased from Q2 to Q3 by 30%, with Glasgow having the most at 40%."
    • "Aggression incidents decreased from Q2 to Q3 in Manchester by 10%, with Manchester having the largest decrease of 15%."

    This approach ensures your report updates dynamically as new data is ingested, and narratives remain accurate and quarter-specific.

     

    Please mark this as solution if it helps you. Appreciate Kudos.

    • RichOB's avatar
      RichOB
      Icon for Post Partisan rankPost Partisan

      I've made the summarized data table but I'm having trouble getting the Count column.:

      Column_count = COUNT('Incidents'[Type of CCIA])

      This is giving me the total of 15 in each cell instead of a 1 count. How can I correct that please?
  • RichOB's avatar
    RichOB
    Icon for Post Partisan rankPost Partisan

    Hi FarhanJeelani  just checking in with this, the first step above you mention is making a table but I'm having trouble with the column count when you said:

    • Count the number of incidents for each combination.

    What measure did you add to the new table to get that column count please?