Forum Discussion
Stacked Bar Chart with Groupings
- 9 years ago
Good morning!
So if the thing creating the problem was using Direct Query mode I changed the data connection to Import instead. There was no reason it had to be Direct Query other than I'm a novice. After changing the data connection I went back to creating a column for the grouping. And it worked!
Thank you for your help!
Hi littlemojopuppy,
Since you have used the direct query mode to connect the database, it is hard to achieve your requirement by dax function because of there are some limitations which you use measure or calculate column on direct mode.
You can use query editor to work through the issue:
Open the "Query editor" and click on "Advanced Editor", then add a custom step.
avg=List.Average(Table.SelectRows(Table.SelectColumns(PerviousStep,"ColumnName"),each _<> null)[ColumnName])
Add a custom column and use above variable to calculate the result.
#"Added Custom" = Table.AddColumn(PerviousStep, "State", each if [ColumnName]>avg then "Over" else if [ColumnName]=avg then "Equal" else "Less")
Screenshots:
Base Table.
Target variable.
Add custom column to check the state.
Save and return to report view, create a visual with the new column as the axis field.
In addition, you can drag the original column to legend field to show the detail information.
Full query:
let
Source = Sql.Databases("xxxxxx"),
qiuyun = Source{[Name="xxxxx"]}[Data],
dbo_Table_1 = qiuyun{[Schema="dbo",Item="Table_1"]}[Data],
avg=List.Average(Table.SelectRows(Table.SelectColumns(dbo_Table_1,"amount"),each _<> null)[amount]),//get the average
#"Added Custom" = Table.AddColumn(dbo_Table_1, "State", each if [amount]>avg then "Over" else if [amount]=avg then "Equal" else "Less")
in
#"Added Custom"
Regards,
Xiaoxin Sheng
Good morning!
So if the thing creating the problem was using Direct Query mode I changed the data connection to Import instead. There was no reason it had to be Direct Query other than I'm a novice. After changing the data connection I went back to creating a column for the grouping. And it worked!
Thank you for your help!